javascript with asp.net

  • Thread starter Thread starter raju
  • Start date Start date
R

raju

Hai,
I am new to ASP.NET, in my application, datagird, itemtemplate, i
am having delete button. If i click that button, I am calling
DeleteCommand,
in that procedure i written the code as given below.

Protected Sub dlTask_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs) Handles
dlTask.DeleteCommand
Dim obutton As Button
obutton = CType(e.Item.FindControl("btnDelete"), Button)
obutton.Attributes.Add("onClick", "alert('Do you want to
Delete?');")
End Sub

When i run this code, If i click the button first time, it doesn't
work. From the second time onwards the alert is working.

What i have to do, to correct this problem?.

Regards,
Raju.
 
you are rendering the javascript on the button only after they click it
once, so it will never work the first time. add it whenever you databind
the grid.

-- bruce (sqlwork.com)
 
This is no wrong,the Handle is double click.

???

There are two problems here:

1) The attribute is not being added until the button is clicked for the
first time - it needs to be added when the data is bound to the control.

2) In order for the user to cancel the postback (i.e. not to delete the
record), the attribute needs to be:

..Attributes.Add("onClick", "return alert('Do you want to Delete?');")
 
Back
Top