Event Handler is not called for Control inside User Control

Discussion in 'ASP .Net' started by ccbalapatel@gmail.com, Apr 4, 2007.

  1. Guest

    Hi,
    We have recently converted our code to ASP.NET 2.0. We have an user
    control that is embedded inside the page. The user control has a link
    button and the event handler for the link button is written inside the
    user control. When the link button is clicked, the page is posted back
    and the page_load method of the user control also executes fine. But,
    the event handler for the link button is not called. The same code
    works fine on ASP.NET 1.1. After some research into this problem, I
    have figured out that the link button's UniqueId is not matching with
    the __EVENTTARGET parameter and hence the event handler is not
    triggered.

    This seems to be a bug in Microsoft ASP.NET framework. Does anyone
    have any workarounds for this problem? Our code is kind of complicated
    with multiple user controls on the same page and all these user
    controls are derived from a base UserControl which contains properties
    common to all the user controls on the page. Moving the event handler
    to the page (from the control) might not work.

    Thanks in advance.
     
    , Apr 4, 2007
    #1
    1. Advertising

  2. wrote:
    > Hi,
    > We have recently converted our code to ASP.NET 2.0. We have an user
    > control that is embedded inside the page. The user control has a link
    > button and the event handler for the link button is written inside the
    > user control. When the link button is clicked, the page is posted back
    > and the page_load method of the user control also executes fine. But,
    > the event handler for the link button is not called. The same code
    > works fine on ASP.NET 1.1. After some research into this problem, I
    > have figured out that the link button's UniqueId is not matching with
    > the __EVENTTARGET parameter and hence the event handler is not
    > triggered.
    >
    > This seems to be a bug in Microsoft ASP.NET framework. Does anyone
    > have any workarounds for this problem? Our code is kind of complicated
    > with multiple user controls on the same page and all these user
    > controls are derived from a base UserControl which contains properties
    > common to all the user controls on the page. Moving the event handler
    > to the page (from the control) might not work.
    >
    > Thanks in advance.
    >


    Funny how the first conclusion is that it's a bug in the framework, that
    has been tested by thousands or even millions of people, rather in your
    own code, that has been tested by a single person... ;)

    Event handlers works just fine in user controls. I just placed two link
    buttons in a user control and tested that the Click even really works,
    you to be really sure that it does work in the exact case that you are
    describing.

    If the UniqueId of the control doesn't match what's used in the
    postback, the id of the control has changed, either during the process
    of creating the first page, or from the first to the second page creation.

    If you for example add controls dynamically to the page, and don't set a
    specific id on the user control (so that it gets an automatic name like
    ctl07), it's id may change if you don't add the exact same controls each
    time. The same also applies to any control that is a naming container,
    so even if you set an id on the user control, but put it in a container
    without a specific id, the id of the user control may change.

    --
    Göran Andersson
    _____
    http://www.guffa.com
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Apr 4, 2007
    #2
    1. Advertising

  3. Guest

    Does the applications tested by thousands have no bugs?

    Anyway, you are right about the simple user control scenario. After
    some testing with a simple page and a simple user control, I have
    realized that the event handler inside the control works. The problem
    I describe is similar to that of http://www.thescripts.com/forum/thread320245.html.

    The reason I came to that conclusion was because the same code works
    in 1.1. I think I need to take a closer look at the page and the
    controls and see why it is not working in 2.0. Obviously, there seems
    to be a difference in the way how these things are handled between 1.1
    and 2.0.
     
    , Apr 5, 2007
    #3
    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. =?Utf-8?B?RGl2eWE=?=

    Button in custom webcontrol - event handler not called

    =?Utf-8?B?RGl2eWE=?=, Apr 30, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,611
    Victor Garcia Aprea [MVP]
    May 1, 2004
  2. =?Utf-8?B?U2hyZXlhc2ggQi4gUGF0ZWw=?=

    Event Handler Not Called.

    =?Utf-8?B?U2hyZXlhc2ggQi4gUGF0ZWw=?=, Aug 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,836
    =?Utf-8?B?U2hyZXlhc2ggUGF0ZWw=?=
    Aug 16, 2004
  3. vatech1993
    Replies:
    4
    Views:
    5,704
    =?Utf-8?B?U8Opcmdpbw==?=
    Dec 11, 2004
  4. Replies:
    1
    Views:
    727
    Damien
    Feb 22, 2007
  5. S_K
    Replies:
    6
    Views:
    1,216
    Robert Dunlop
    Nov 8, 2007
Loading...

Share This Page