UserControl click event won't fire

Discussion in 'ASP .Net Web Controls' started by Mark Sisson, Dec 2, 2003.

  1. Mark Sisson

    Mark Sisson Guest

    I've got a custom usercontrol (UC1) that dynamically loads another
    custom usercontrols (UC2) during it's Init event. Both controls have
    LinkButtons with click events. The LinkButton from UC1 properly goes
    to it's click-event handler but the LinkButton from UC2 does not fire
    it's associated click event.


    Are there problem in having nested Usercontrols fire events if they're
    created through code?

    TIA
     
    Mark Sisson, Dec 2, 2003
    #1
    1. Advertising

  2. Mark Sisson

    Thijs Guest

    I think you're experiencing the same problem as I am. The problem is that
    ASP.NET is unable to restore the viewstate of a dynamically loaded control
    after a postback. I'm searching for a way to do this manually now.

    Regards,

    Thijs

    "Mark Sisson" <> schreef in bericht
    news:...
    > I've got a custom usercontrol (UC1) that dynamically loads another
    > custom usercontrols (UC2) during it's Init event. Both controls have
    > LinkButtons with click events. The LinkButton from UC1 properly goes
    > to it's click-event handler but the LinkButton from UC2 does not fire
    > it's associated click event.
    >
    >
    > Are there problem in having nested Usercontrols fire events if they're
    > created through code?
    >
    > TIA
     
    Thijs, Dec 2, 2003
    #2
    1. Advertising

  3. Mark Sisson

    Chris Thayer Guest

    This should work correctly. I created an example like you described and it
    worked as expected. Here is the source of UC1:

    <%@ control language="C#" classname="WebUserControl"%>
    <%@ register tagprefix="uc" tagname="uc2" src="~/WebUserControl2.ascx" %>

    <script runat="server">
    protected override void OnInit(EventArgs e)
    {
    WebUserControl2 uc2 =
    (WebUserControl2)LoadControl("WebUserControl2.ascx");
    Controls.Add(uc2);
    base.OnInit(e);
    }

    void LinkButton1_Click(object sender, EventArgs e)
    {
    Page.Response.Write("this is from LinkButton1_Click<br>");
    }

    </script>

    <asp:linkbutton runat="server" id="LinkButton1" onclick="LinkButton1_Click"
    >LinkButton1</asp:linkbutton><br />


    and this is the source of UC2:

    <%@ control language="C#" classname="WebUserControl2"%>

    <script runat="server">

    void LinkButton2_Click(object sender, EventArgs e)
    {
    Page.Response.Write("this is from LinkButton2_Click<br>");
    }
    </script>

    <asp:linkbutton runat="server" id="LinkButton2" onclick="LinkButton2_Click"
    >LinkButton2</asp:linkbutton>


    Hope that helps,
    Chris Thayer
    --------------------
    >From: (Mark Sisson)
    >Newsgroups:

    microsoft.public.dotnet.framework.aspnet.buildingcontrols,microsoft.public.d
    otnet.framework.aspnet.webcontrols
    >Subject: UserControl click event won't fire
    >Date: 2 Dec 2003 08:03:04 -0800
    >Organization: http://groups.google.com
    >Lines: 11
    >Message-ID: <>
    >NNTP-Posting-Host: 68.99.177.203
    >Content-Type: text/plain; charset=ISO-8859-1
    >Content-Transfer-Encoding: 8bit
    >X-Trace: posting.google.com 1070380984 8237 127.0.0.1 (2 Dec 2003 16:03:04

    GMT)
    >X-Complaints-To:
    >NNTP-Posting-Date: Tue, 2 Dec 2003 16:03:04 +0000 (UTC)
    >Path:

    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfee
    d01.sul.t-online.de!t-online.de!fu-berlin.de!postnews1.google.com!not-for-ma
    il
    >Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webcontrols:16577
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:8322
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    >
    >I've got a custom usercontrol (UC1) that dynamically loads another
    >custom usercontrols (UC2) during it's Init event. Both controls have
    >LinkButtons with click events. The LinkButton from UC1 properly goes
    >to it's click-event handler but the LinkButton from UC2 does not fire
    >it's associated click event.
    >
    >
    >Are there problem in having nested Usercontrols fire events if they're
    >created through code?
    >
    >TIA
    >
     
    Chris Thayer, Dec 10, 2003
    #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. Chad
    Replies:
    4
    Views:
    8,341
  2. Amy
    Replies:
    0
    Views:
    992
  3. Mark Sisson

    UserControl click event won't fire

    Mark Sisson, Dec 2, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    120
    Thijs
    Dec 2, 2003
  4. CalSun

    dynamic loading - click event won't fire

    CalSun, Jul 8, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    144
    CalSun
    Jul 20, 2005
  5. Mark Sisson

    UserControl click event won't fire

    Mark Sisson, Dec 2, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    120
    Mark Sisson
    Dec 2, 2003
Loading...

Share This Page