Dynamically Loaded User Control's Event Does Not Work

  1. #1

    Dynamically Loaded User Control's Event Does Not Work


    I have a user control that has a simple button and put a message to the screen. When I press the button a javascript error occur.

    Here is my user control's asp code

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SampleUserControl.ascx.cs" Inherits="ExtNetUCTest.SampleUserControl" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     <form id="Form1" runat="server">        
            Title="Example Wizard" 
                <ext:Button ID="btnNext" runat="server" Text="Next" Icon="NextGreen">
                        <Click Handler="#{DirectMethods}.Next_Click();" />
    User Control's Code Behind
    namespace ExtNetUCTest
        public partial class SampleUserControl : System.Web.UI.UserControl
            protected void Page_Load(object sender, EventArgs e)
            protected void Next_Click(object sender, DirectEventArgs e)
                X.Msg.Alert("Test", "Test");
    My Default.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ExtNetUCTest.Default" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
            <ext:ResourceManager ID="MyResourceManager" runat="server" />
            <ext:Viewport  runat="server">
                    <ext:VBoxLayoutConfig Align="Stretch"></ext:VBoxLayoutConfig>
                    <ext:Panel runat="server" ID="myViewportHeader" Height="50"></ext:Panel>
                    <ext:Panel runat="server" ID="myViewportBase" Flex="1">
                    <ext:Panel runat="server" ID="myViewportFooter" Height="25"></ext:Panel>
    And finally Default.aspx.cs
    namespace ExtNetUCTest
        public partial class Default : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)
                if (X.IsAjaxRequest)
                var btn = new Button(new Button.Config()
                    Text = "clickme"
                btn.Listeners.Click.Handler = "App.direct.AButtonClick();";
            public void AButtonClick()
                var uc = LoadControl("~/SampleUserControl.ascx") as UserControl;
    I press clickme and the user controls loaded as expected, but when i press Next Button in the user control, the following javascript message appears : "Uncaught TypeError: Cannot call method 'Next_Click' of undefined ".

    Thanks in advance.
    Last edited by kcelik; Oct 09, 2012 at 6:30 AM.
  2. #2
    UserControl must be recreated on each request, it is ASP.NET requirement for dynamic controls

Similar Threads

  1. Replies: 2
    Last Post: Dec 08, 2011, 1:00 PM
  2. [CLOSED] [1.0] User Control loaded several times
    By FVNoel in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 07, 2011, 10:33 AM
  3. [CLOSED] Dynamic loaded user control height problem
    By Suntico in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: Jun 27, 2011, 8:54 AM
  4. Replies: 32
    Last Post: Jan 11, 2011, 9:53 AM
  5. Replies: 2
    Last Post: Apr 15, 2010, 5:33 AM

Posting Permissions