Adding delete confirmation to repeating controls

Last post 07-08-2004 9:22 AM by u2orange. 4 replies.

Sort Posts:

  • Adding delete confirmation to repeating controls

    11-05-2002, 11:19 AM
    • Member
      25 point Member
    • Officer Murphy
    • Member since 10-01-2002, 5:17 PM
    • South Dakota
    • Posts 5
    Here's another way to add to the myriad of ways already identified to add a delete confirmation in the IBS Portal. This method is specific however to the databound repeating controls.

    in your ascx or aspx page wherever you have a button that is to be used for deleting in your code simply add this to the definition...

    ondatabinding="BtnDelete_DataBinding"

    then somewhere in your code add this eventhandler....

    Protected Sub BtnDelete_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
    Dim BtnDelete As ImageButton = CType(sender, ImageButton)
    BtnDelete.Attributes.Add("onclick", "javascript: return confirm('Are you sure you wish to delete this item?');")
    End Sub

    what you gain from doing it this way is not having to loop through the entire controls collection of a dataitem to find the delete button, or if you have multiple repeating controls on the page, you don't have to override the repeater controls itemdatabound event twice.
  • Re: Adding delete confirmation to repeating controls

    11-05-2002, 11:57 AM
    • Member
      25 point Member
    • Officer Murphy
    • Member since 10-01-2002, 5:17 PM
    • South Dakota
    • Posts 5
    Sorry, I'm not really sure what i was thinking, don't use databinding, use the Init event instead....

    onInit="BtnDelete_Init"


    VB
    ----------------
    Protected Sub BtnDelete_Init(ByVal sender As Object, ByVal e As EventArgs)
    Dim BtnDelete As ImageButton = CType(sender, ImageButton)
    BtnDelete.Attributes.Add("onclick", "javascript: return confirm('Are you sure you wish to delete this item?');")
    End Sub

    C#
    -----------------
    protected void BtnDelete_Init(Object sender, EventArgs e)
    {
    ImageButton BtnDelete = (ImageButton) sender
    BtnDelete.Attributes.Add("onclick","javascript: return confirm('Are you sure you wish to delete this item?');")
    }
  • Re: Adding delete confirmation to repeating controls

    11-05-2002, 9:15 PM
    • Member
      345 point Member
    • caschbre
    • Member since 10-11-2002, 11:34 AM
    • Posts 69
    Where does the onInit="BtnDelete_Init" call go? I image the BtnDelete_Init(..) goes in the code behind page.
  • Re: Adding delete confirmation to repeating controls

    11-06-2002, 8:47 AM
    • Member
      25 point Member
    • Officer Murphy
    • Member since 10-01-2002, 5:17 PM
    • South Dakota
    • Posts 5
    in your aspx page...
    <asp:imagebutton id="myButton" runat="server" oninit="BtnDelete_Init" />

    for clarity reasons in your code you may also want to use BtnDelete as your id for the button, but there is no rule that says you have to.
  • Re: Adding delete confirmation to repeating controls

    07-08-2004, 8:33 AM
    • Member
      215 point Member
    • u2orange
    • Member since 06-06-2003, 1:27 PM
    • Posts 45
    This is also exactly what I was looking for!

    I owe you a virtual beer, Thanks.
Page 1 of 1 (5 items)