Checkboxlist inside Repeater - doesn't fire click event for Checkboxlist

Discussion in 'ASP .Net' started by JD, Jun 15, 2004.

  1. JD

    JD Guest

    Hello,
    I have a problem with checkboxlist inside Repeater (in ASP.NET page).
    I am able to create Checkboxlist and bind it (inside Repeater_ItemBound -
    including setting checked/unchecked). Checkboxlist has Autopostback=true so
    whenever I click on checkbox, the page is submitted to the server.

    Here starts my problem:
    I am not able to capture the click event of checkbox list to find out which
    checkbox was clicked (which generated click event) and retrieve the value
    associated with it (for further processing).
    I have List_SelectedIndexChanged function but it never fires. I am obviously
    missing something, I don't undestand event bubling enough.
    Any idea? Any help?
    Thanks
    JD
     
    JD, Jun 15, 2004
    #1
    1. Advertising

  2. JD,

    I have some sample code in the code library of my web site,
    www.aboutfortunate.com, which shows how to get the value of the row clicked
    in a datagrid when a check box is checked.

    While it doesn't use a repeater or a checkbox list the process is very
    similar to what you need to do and quite a bit simpler so it may be good for
    you to give it a glance. It may help.

    Click the "code library" link on the top right of the home page and then use
    the search box to search for: "reference a checkbox" or something similar
    and you'll find it.

    Pay particular attention to how I'm using "oncheckedchanged" in the check
    boxe's auto post back to call the proper subroutine when the checkbox is
    clicked.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "JD" <> wrote in message
    news:...
    > Hello,
    > I have a problem with checkboxlist inside Repeater (in ASP.NET page).
    > I am able to create Checkboxlist and bind it (inside Repeater_ItemBound -
    > including setting checked/unchecked). Checkboxlist has Autopostback=true

    so
    > whenever I click on checkbox, the page is submitted to the server.
    >
    > Here starts my problem:
    > I am not able to capture the click event of checkbox list to find out

    which
    > checkbox was clicked (which generated click event) and retrieve the value
    > associated with it (for further processing).
    > I have List_SelectedIndexChanged function but it never fires. I am

    obviously
    > missing something, I don't undestand event bubling enough.
    > Any idea? Any help?
    > Thanks
    > JD
    >
    >
     
    S. Justin Gengo, Jun 15, 2004
    #2
    1. Advertising

  3. JD

    marinov Guest

    have you tried to create the event of the checkboxlist like

    <asp:CheckBoxList id=.... OnSelectedIndexChanged="YourEventName"
    AutoPostBack=True>
    .....

    this will tell to the asp.net that when a checkbox is clicked the
    YourEventName event will fired, BUT you have to declare your event as Public
    other wise asp.net won't find it :(

    Hope This Helps
    Regards
    Martin Marinov

    "JD" <> wrote in message
    news:...
    > Hello,
    > I have a problem with checkboxlist inside Repeater (in ASP.NET page).
    > I am able to create Checkboxlist and bind it (inside Repeater_ItemBound -
    > including setting checked/unchecked). Checkboxlist has Autopostback=true

    so
    > whenever I click on checkbox, the page is submitted to the server.
    >
    > Here starts my problem:
    > I am not able to capture the click event of checkbox list to find out

    which
    > checkbox was clicked (which generated click event) and retrieve the value
    > associated with it (for further processing).
    > I have List_SelectedIndexChanged function but it never fires. I am

    obviously
    > missing something, I don't undestand event bubling enough.
    > Any idea? Any help?
    > Thanks
    > JD
    >
    >
     
    marinov, Jun 15, 2004
    #3
  4. Hi,

    an important thing in all this is that you recreate the control before the
    viewstate is restored, for info when everything happens see this link:
    http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp .
    If the same control structure doesn't exists when the viewstate is restored
    it will not be able to "discover" the events. As Marintov wrote you have
    also to define where this event is going to be handled in the "tag" of the
    checkbox list.

    So what does all this mean, basically this (only pseudo code for how the
    behind code could be structured.):


    Sub Page_Init()
    // code to bind your repeater
    // after the page init the viewstate will be restored.
    End Sub

    Sub ChkBoxlist_IndexChange()
    // here is your event!
    // if you want to access some other control that is within the same
    repeater element use the parent property of the reperater.
    End Sub


    I hope this clears things up
    Cheers
    Cristian



    "marinov" <> wrote in message
    news:...
    > have you tried to create the event of the checkboxlist like
    >
    > <asp:CheckBoxList id=.... OnSelectedIndexChanged="YourEventName"
    > AutoPostBack=True>
    > ....
    >
    > this will tell to the asp.net that when a checkbox is clicked the
    > YourEventName event will fired, BUT you have to declare your event as

    Public
    > other wise asp.net won't find it :(
    >
    > Hope This Helps
    > Regards
    > Martin Marinov
    >
    > "JD" <> wrote in message
    > news:...
    > > Hello,
    > > I have a problem with checkboxlist inside Repeater (in ASP.NET page).
    > > I am able to create Checkboxlist and bind it (inside

    Repeater_ItemBound -
    > > including setting checked/unchecked). Checkboxlist has Autopostback=true

    > so
    > > whenever I click on checkbox, the page is submitted to the server.
    > >
    > > Here starts my problem:
    > > I am not able to capture the click event of checkbox list to find out

    > which
    > > checkbox was clicked (which generated click event) and retrieve the

    value
    > > associated with it (for further processing).
    > > I have List_SelectedIndexChanged function but it never fires. I am

    > obviously
    > > missing something, I don't undestand event bubling enough.
    > > Any idea? Any help?
    > > Thanks
    > > JD
    > >
    > >

    >
    >
     
    Cristian Suazo, Jun 16, 2004
    #4
  5. JD

    dbeltran

    Joined:
    Sep 29, 2006
    Messages:
    1
    Hi There,

    Where you able to find out how to process clicks on the checkboxlist inside a repeater?
    Please let me know, as I am trying to get the same thing to work.

    Thank you!

    DBeltran

     
    dbeltran, Sep 29, 2006
    #5
  6. JD

    NetArchitect

    Joined:
    Aug 8, 2007
    Messages:
    1
    Fire event from dropdownlist inside repeater or datagrid

    Declare the event on your dropdownlist placed inside your repeater or datagrid

    <asp:DropDownList
    OnSelectedIndexChanged="GridItems_SelectedIndexChanged" ...>

    Then in your code behind:

    protected void GridItems_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    //You get the line that threw the event
    DataGridItem dgi = (DataGridItem)(((Control)sender).NamingContainer);

    //You can get the value of the dropdownlist that fired the event
    Trace.Warn("selected index: " + ((DropDownList)dgi.Cells[3].Controls[1]).SelectedIndex.ToString());

    ...

    }
     
    NetArchitect, Aug 8, 2007
    #6
    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. Henke
    Replies:
    1
    Views:
    485
  2. Chu
    Replies:
    2
    Views:
    911
    Winista
    Apr 10, 2006
  3. Amy
    Replies:
    0
    Views:
    998
  4. Nathan Sokalski
    Replies:
    0
    Views:
    1,077
    Nathan Sokalski
    Jan 15, 2009
  5. MU
    Replies:
    0
    Views:
    569
Loading...

Share This Page