Link to home
Start Free TrialLog in
Avatar of miyahira
miyahiraFlag for Peru

asked on

Problems with Attributes.Add("onclick",.... and MyTextBox_TextChanged

Hello,

Controls on webpage:
 - Datagrid
 - TextBox

Datagrid has Delete button:

<asp:TemplateColumn HeaderText="Borrar">
      <HeaderStyle Width="10%"></HeaderStyle>
      <ItemStyle HorizontalAlign="Center"></ItemStyle>
      <ItemTemplate>
            <asp:ImageButton id="btnDelete" runat="server" CommandName="Delete"></asp:ImageButton>
      </ItemTemplate>
</asp:TemplateColumn>

At function MyDatagrid_ItemCreated , I add attributes to that Delete button. So, when the user click on Delete button, then it's showed a confirmation message before to proceed to delete the record.

Private Sub MyDatagrid_ItemCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles MyDatagrid.ItemCreated
        If (e.Item.ItemIndex > -1) Then
            Dim mydeletebutton As TableCell
            mydeletebutton = e.Item.Cells(0)
            mydeletebutton.Attributes.Add("onclick", "return alert('Are you sure you will delete record...?');")
        End If
End Sub

Now my problem is that the user has to write on the TextBox. When user focus on the TextBox and then press ENTER, then it is showed windows message: 'Are you sure you will delete record...?'.
I tried to put hide buttons on the webpage, but no success.
Allways when the user hit ENTER on the TextBox, the message appears on screen.

This function is never raised:

    Private Sub MyTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyTextBox.TextChanged
         ' Some code goes here ....
    End Sub

How could I solve that?
Thank you!
Avatar of kraffay
kraffay

Check you tab index.  You may be able to get the focus to go to a control after the textbox
Not sure where the problem is based on the code you've provided.

Here is a very good tutorial on adding client-side confirmation box for deleting datagrid items.  Note he uses the ItemDataBound instead of ItemCreated:

http://aspnet.4guysfromrolla.com/articles/090402-1.aspx

Hope that helps
-Ian
Avatar of miyahira

ASKER

Funny. Only solution I found: I had to put a button with minimal dimensions above the datagrid, so when the user press Enter at the TextBox, then Minimal_Dimesions_Button will fire nothing
ASKER CERTIFIED SOLUTION
Avatar of Xeavn
Xeavn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial