web user control events

Discussion in 'ASP .Net Web Controls' started by Greg, Jul 28, 2004.

  1. Greg

    Greg Guest

    I have an ascx web user control that has a button and listbox. I want to be able to expose the click event of the button and return the selected value in the listbox to the aspx page that uses the control. Or, I could capture the click event by the aspx page and expose the selected item property of the listbox. I was having problems just capturing the event on the aspx page and I think it's because the control is being loaded dynamically (I think the control is being lost on postback and the control is reloaded only after the click event tried to fire???). The aspx page might be loading 0 to unlimited number of these controls, one after another ... so what I did was add the eventhandler immediately after I added each control instead of in the OnInit event. Now, the page hits the event, but it always thinks that the event is being triggered by the last-loaded control. Can anyone help or at least point me in the right direction? Do I need to build a control collection of some sort and just add that control collection to the aspx page? How would I go about that?
     
    Greg, Jul 28, 2004
    #1
    1. Advertising

  2. Greg

    Greg Guest

    I am able to handle the control, but only the last control I dynamically put on the page. I have a web user control, but I might have 1 or more of them on a single page. Somehow I guess I have to have the controls in a collection(?) and in the onclick event method be able to determine which user control had the button which was clicked. As it stands now, it always assumes the event was fired from the control that was placed last on the page.

    "ranganh" wrote:

    > Dear Greg,
    >
    > For handling controls present in the usercontrol, you need to create an instance of the usercontrol and use the find control method to access those controls. That would be pretty straight forward instead of creating it in init method.
    >
    > Check my blog url below, where in have implemented getting the selected value of a dropdownlist in an usercontrol from the container page.
    >
    > http://aspnet_harish.blogspot.com/2004/07/selected-item-in-dropdownlist-in.html
    >
    > Hope it helps.
    >
    > "Greg" wrote:
    >
    > > I have an ascx web user control that has a button and listbox. I want to be able to expose the click event of the button and return the selected value in the listbox to the aspx page that uses the control. Or, I could capture the click event by the aspx page and expose the selected item property of the listbox. I was having problems just capturing the event on the aspx page and I think it's because the control is being loaded dynamically (I think the control is being lost on postback and the control is reloaded only after the click event tried to fire???). The aspx page might be loading 0 to unlimited number of these controls, one after another ... so what I did was add the eventhandler immediately after I added each control instead of in the OnInit event. Now, the page hits the event, but it always thinks that the event is being triggered by the last-loaded control. Can anyone help or at least point me in the right direction? Do I need to build a control collection of some sort and just add that control collection to the aspx page? How would I go about that?
     
    Greg, Jul 29, 2004
    #2
    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. Sunkam Santhoshi

    Events for menu user control using ie web control

    Sunkam Santhoshi, Dec 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    413
    Sunkam Santhoshi
    Dec 16, 2003
  2. ABC
    Replies:
    1
    Views:
    2,658
    Larry
    Oct 4, 2005
  3. ABC
    Replies:
    0
    Views:
    491
  4. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    387
    Chris
    Aug 30, 2005
  5. ABC
    Replies:
    0
    Views:
    215
Loading...

Share This Page