469,072 Members | 1,808 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,072 developers. It's quick & easy.

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!

Nov 17 '06 #1
1 5241
MyTextBox_TextChanged will not fire until postback as this is a server
side event.

when the user is pressing enter, it is firing the clientside onclick
event of the delete button, which is why the alert box is showing.

one thing is that if you don't want it to behave like this, the delete
button should not be receiving focus.. try setting the focus to the
default button you want to react to on enter.

hope this helps

~kcf

On Nov 17, 10:40 am, "Big George" <jbet...@gmail.comwrote:
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!
Nov 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Eric Smith | last post: by
8 posts views Thread by nicolas.sanguinetti | last post: by
16 posts views Thread by Bret Pehrson | last post: by
6 posts views Thread by Samuel M. Smith | last post: by
3 posts views Thread by sagar | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.