javascript with asp.net

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.
 
B

bruce barker

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)
 
M

Mark Rae [MVP]

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?');")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top