Help With Addding Attribute to Button In Data Repeater

Discussion in 'ASP .Net Web Controls' started by Sal D'Ambra, Jan 1, 2004.

  1. Sal D'Ambra

    Sal D'Ambra Guest

    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
    --
    Sal D'Ambra
    Blue Ridge Summit, PA
     
    Sal D'Ambra, Jan 1, 2004
    #1
    1. Advertising

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

    "Sal D'Ambra" <> wrote in message
    news:...
    > 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
    > --
    > Sal D'Ambra
    > Blue Ridge Summit, PA
    >
    >
     
    Alessandro Zifiglio, Jan 2, 2004
    #2
    1. Advertising

  3. Sal D'Ambra

    Sal D'Ambra Guest

    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
    --
    Sal D'Ambra
    Blue Ridge Summit, PA


    "Alessandro Zifiglio" <> wrote in
    message news:Dv3Jb.22585$...
    > 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
    >
    > "Sal D'Ambra" <> wrote in message
    > news:...
    > > 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
    > > --
    > > Sal D'Ambra
    > > Blue Ridge Summit, PA
    > >
    > >

    >
    >
     
    Sal D'Ambra, Jan 2, 2004
    #3
  4. your welcome Sal ;)
    Enjoy the new year.
    "Sal D'Ambra" <> wrote in message
    news:...
    > 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
    > --
    > Sal D'Ambra
    > Blue Ridge Summit, PA
    >
    >
    > "Alessandro Zifiglio" <> wrote in
    > message news:Dv3Jb.22585$...
    > > 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
    > >
    > > "Sal D'Ambra" <> wrote in message
    > > news:...
    > > > 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
    > > > --
    > > > Sal D'Ambra
    > > > Blue Ridge Summit, PA
    > > >
    > > >

    > >
    > >

    >
    >
     
    Alessandro Zifiglio, Jan 2, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    904
  2. Replies:
    0
    Views:
    2,936
  3. Gregory

    <DIV> addding text from code behind.

    Gregory, Oct 10, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    15,887
    Gregory
    Oct 10, 2005
  4. news.microsoft.com
    Replies:
    3
    Views:
    865
    Gregory A. Beamer
    Apr 28, 2010
  5. Samuel Ashley via .NET 247

    Using Radio button in a Data Repeater

    Samuel Ashley via .NET 247, Mar 31, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    299
    Rajesh C K R
    Mar 31, 2005
Loading...

Share This Page