Help With Addding Attribute to Button In Data Repeater

S

Sal D'Ambra

Hello All,

I have a data repeater control and it has a 'Delete' and 'Edit' button for
each row. I would like to add a pop-up via javascript so when a user clicks
the 'Delete' button it asks if they are sure. I know I can add an attribute
for onclick and the name of the script for a button but.... I can't figure
out how to do this for the buttons which are dynamically created. I am
looking about in the Repeater.OnItemCreated but frankly I'm stumped. Thanks
in advance for any help.

Sal
 
A

Alessandro Zifiglio

You need to do it in the item databound method of your repeater control :

Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
Repeater1.ItemDataBound
Dim MyDeleteButton As LinkButton
MyDeleteButton = CType(e.Item.FindControl("Linkbutton4"),
LinkButton)
MyDeleteButton.Attributes.Add("OnClick", _
"return confirm('Are you Sure you want to delete this record?');")
End Sub
 
S

Sal D'Ambra

Alessandro ,

Thank you - I have it working. You have no idea how long I spent on that.

For anyone else with this issue here is the code which which works for me:

Private Sub EducationRepeater_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
EducationRepeater.ItemDataBound

Dim MyDeleteButton As Button

If Not IsNothing(e.Item.FindControl("DeleteButton")) Then
MyDeleteButton = CType(e.Item.FindControl("DeleteButton"), Button)
MyDeleteButton.Attributes.Add("OnClick", "confirmDelete()")
End If

End Sub

Sal
 
A

Alessandro Zifiglio

your welcome Sal ;)
Enjoy the new year.
Sal D'Ambra said:
Alessandro ,

Thank you - I have it working. You have no idea how long I spent on that.

For anyone else with this issue here is the code which which works for me:

Private Sub EducationRepeater_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
EducationRepeater.ItemDataBound

Dim MyDeleteButton As Button

If Not IsNothing(e.Item.FindControl("DeleteButton")) Then
MyDeleteButton = CType(e.Item.FindControl("DeleteButton"), Button)
MyDeleteButton.Attributes.Add("OnClick", "confirmDelete()")
End If

End Sub

Sal
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top