[CLOSED] Dynamic userControl load with DirectMethod

  1. #1

    [CLOSED] Dynamic userControl load with DirectMethod

    Hi,

    Since DirectMethods TabChange event doesn't work (infinitive loop after first tab change which I described here: http://forums.ext.net/showthread.php...vent-TabChange)

    I've decided to give a try DirectMethods which I've put in My UserControl Test.ascx

    here's my sample used v1.5.0 )couldn't find v1.6:(:

    Page.master
    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Page.master.cs" Inherits="Ext1._6Test.Page" %>
    
    <%@ 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 id="Head1" runat="server">
        <title></title>
        <asp:ContentPlaceHolder ID="head" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server"></ext:ResourceManager>
            <ext:Viewport runat="server">
                <LayoutConfig>
                    <ext:VBoxLayoutConfig runat="server" Align="Stretch"/>
                </LayoutConfig>
                <Items>
                    <ext:Container runat="server" Height="70">
                        <LayoutConfig>
                            <ext:VBoxLayoutConfig runat="server" Align="Stretch"/>
                        </LayoutConfig>
                        <Items>
                            <ext:Container runat="server" Height="40">
                                <Content>
                                    Top
                                </Content>
                            </ext:Container>
                            <ext:Toolbar runat="server" Height="30">
                                <Items>
                                    <ext:Button runat="server" Text="Start" OnClientClick="window.location.href='Start.aspx'"></ext:Button>
                                    <ext:Button runat="server" Text="Test" OnClientClick="window.location.href='Test.aspx'"></ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </Items>
                    </ext:Container>
                    <ext:Container runat="server" Layout="Fit" Flex="1">
                        <Content>
                            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            
                            </asp:ContentPlaceHolder>
                        </Content>
                    </ext:Container>
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
    pages Start and Test .aspx
    <%@ Page Title="" Language="C#" MasterPageFile="~/Page.Master" AutoEventWireup="true" CodeBehind="Start.aspx.cs" Inherits="Ext1._6Test.Start" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <ext:Container runat="server" Layout="Fit">
            <Items>
                <ext:ButtonBase runat="server" Text="btn Start Page"></ext:ButtonBase>
            </Items>
        </ext:Container>
    </asp:Content>
    
    <%-- Test.aspx --%>
    <%@ Page Title="" Language="C#" MasterPageFile="~/Page.Master" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="Ext1._6Test.Test" %>
    <%@Register  tagPrefix="uc" tagName="Test" src="controls/Test.ascx"%>
    <%@Register assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <ext:Container runat="server" Layout="Fit">
            <Content>
                <uc:Test runat="server"/>
            </Content>
        </ext:Container>
    </asp:Content>
    userControls Test and DynamicControl *.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="Ext1._6Test.controls.Test" %>
    <%@ Import Namespace="Ext1._6Test.controls" %>
    <%@ Register TagPrefix="ext" Namespace="Ext.Net" Assembly="Ext.Net" %>
    
    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            [DirectMethod]
            public void LoadControl(Ext.Net.Panel panel)
            {
                DynamicControl dynamicControl = (DynamicControl) LoadControl("/DynamicControl.ascx");
                dynamicControl.ID = "dynamic_Control_in_" + panel.ID;
                panel.ContentControls.Add(dynamicControl);
                panel.UpdateContent();
            }
    protected void tPanel_TabChange(object sender, DirectEventArgs e)
            {
                TabPanel tPanel = (TabPanel) sender;
                Ext.Net.Panel panel = (Ext.Net.Panel)tPanel.Items[tPanel.ActiveIndex];
                if (panel != null && panel.Items.Count==0)
                {
                    DynamicControl dc = (DynamicControl) LoadControl("DynamicControl.ascx");
                    dc.ID = "dynamicControl_" + panel.ID;
                    panel.ContentControls.Add(dc);
                    panel.UpdateContent();
                }
            }
    </script>
    
    <ext:Container runat="server" Layout="Border" ID="container">
        <Items>
            <ext:Panel runat="server" Region="North" Height="40">
                <Items>
                    <ext:Button runat="server" Text="btn north"></ext:Button>
                </Items>
            </ext:Panel>
            <ext:Panel runat="server" Region="Center">
                <Items>
                    <ext:TextField runat="server" Text="center"></ext:TextField>
                </Items>
            </ext:Panel>
            <ext:TabPanel runat="server" Region="South" Height="300" Collapsed="true" Collapsible="False" ActiveIndex="0">
                <Items>
                    <ext:Panel runat="server" ID="tab1" Title="Tab1"></ext:Panel>
                    <ext:Panel runat="server" ID="tab2" Title="Tab2"></ext:Panel>
                </Items>
                <Listeners>
                    <Activate Handler="Ext.net.DirectMethods.LoadControl(p)"></Activate>
                </Listeners>
    <DirectEvents>
                    <TabChange Before="if (!this.ignoredFirstTabChange) { this.ignoredFirstTabChange = true; return false; }" OnEvent="tPanel_TabChange"></TabChange>
                </DirectEvents>
            </ext:TabPanel>
        </Items>
    </ext:Container>
    
    <%-- DynamicControl.ascx --%>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DynamicControl.ascx.cs" Inherits="Ext1._6Test.controls.DynamicControl" %>
    <%@Register assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" %>
    
    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
            {
                txt.Text = this.ID;
            }
    </script>
    
    <ext:TextField runat="server" ID="txt"></ext:TextField>
    Question is why this DirectMethod doesn't work (doesn't even be call after click in second tab).

    Am I miss something? How can I handle this?

    Regards,
    ViDom

    Edit:
    Tryed also change this:
    <Activate Handler="Ext.net.DirectMethods.LoadControl(p)"></Activate>
    to:
    <Activate Handler="Ext.net.DirectMethods.Test.LoadControl(p)"></Activate>
    It's make no changes still not working.
    Last edited by Daniil; Oct 04, 2012 at 6:19 PM. Reason: [CLOSED]
  2. #2
    Hi @ViDom,

    Quote Originally Posted by ViDom View Post
    Since DirectMethods TabChange event doesn't work (infinitive loop after first tab change which I described here: http://forums.ext.net/showthread.php...vent-TabChange)
    I have updated this thread with a new post. Please follow to read.


    Quote Originally Posted by ViDom View Post
    I've decided to give a try DirectMethods which I've put in My UserControl Test.ascx
    Then you should recreate this user controls during each request if you need to use its DirectMethods.

    Quote Originally Posted by ViDom View Post
    here's my sample used v1.5.0 )couldn't find v1.6:(:
    There is no such version yet. It will be the next v1 release.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @ViDom,



    I have updated this thread with a new post. Please follow to read.




    Then you should recreate this user controls during each request if you need to use its DirectMethods.



    There is no such version yet. It will be the next v1 release.
    I've seen that post today and it's work but problem is I don't have custom control inherited from Ext.Net. I've made edit my first post in this topic and it's not working. Please confirm.
  4. #4
    Quote Originally Posted by ViDom View Post
    I've made edit my first post in this topic and it's not working. Please confirm.
    Please clarify where did you edit?
  5. #5
    Quote Originally Posted by Daniil View Post
    Please clarify where did you edit?
    #1 post

    Test.ascx control

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Test.ascx.cs" Inherits="Ext1._6Test.controls.Test" %>
    <%@ Import Namespace="Ext1._6Test.controls" %>
    <%@ Register TagPrefix="ext" Namespace="Ext.Net" Assembly="Ext.Net" %>
     
    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
            {
     
            }
     
            [DirectMethod]
            public void LoadControl(Ext.Net.Panel panel)
            {
                DynamicControl dynamicControl = (DynamicControl) LoadControl("/DynamicControl.ascx");
                dynamicControl.ID = "dynamic Control in " + panel.ID;
                panel.ContentControls.Add(dynamicControl);
                panel.UpdateContent();
            }
    protected void tPanel_TabChange(object sender, DirectEventArgs e)
            {
                TabPanel tPanel = (TabPanel) sender;
                Ext.Net.Panel panel = (Ext.Net.Panel)tPanel.Items[tPanel.ActiveIndex];
                if (panel != null && panel.Items.Count==0)
                {
                    DynamicControl dc = (DynamicControl) LoadControl("DynamicControl.ascx");
                    dc.ID = "dynamicControl " + panel.ID;
                    panel.ContentControls.Add(dc);
                    panel.UpdateContent();
                }
            }
    </script>
     
    <ext:Container runat="server" Layout="Border" ID="container">
        <Items>
            <ext:Panel runat="server" Region="North" Height="40">
                <Items>
                    <ext:Button runat="server" Text="btn north"></ext:Button>
                </Items>
            </ext:Panel>
            <ext:Panel runat="server" Region="Center">
                <Items>
                    <ext:TextField runat="server" Text="center"></ext:TextField>
                </Items>
            </ext:Panel>
            <ext:TabPanel runat="server" Region="South" Height="300" Collapsed="true" Collapsible="False" ActiveIndex="0">
                <Items>
                    <ext:Panel runat="server" ID="tab1" Title="Tab1"></ext:Panel>
                    <ext:Panel runat="server" ID="tab2" Title="Tab2"></ext:Panel>
                </Items>
                <Listeners>
                    <Activate Handler="Ext.net.DirectMethods.LoadControl(p)"></Activate>
                </Listeners>
    <DirectEvents>
                    <TabChange Before="if (!this.ignoredFirstTabChange) { this.ignoredFirstTabChange = true; return false; }" OnEvent="tPanel_TabChange"></TabChange>
                </DirectEvents>
            </ext:TabPanel>
        </Items>
    </ext:Container>
  6. #6
    Than you for the sample, but, seems, it is from another thread, isn't that so?
  7. #7
    Quote Originally Posted by Daniil View Post
    Than you for the sample, but, seems, it is from another thread, isn't that so?
    No this is from this thread it's similar to another thread but not the same here I don't load custom control but usercontrol.
  8. #8
    Ok, thank you for clarification.

    I still can't see where you recreate the user control during each request to get its DirectMethod working.
  9. #9
    Quote Originally Posted by Daniil View Post
    Ok, thank you for clarification.

    I still can't see where you recreate the user control during each request to get its DirectMethod working.
    Why should I recreate control which is in markup?

    I think that this user control is automatically recreated each time because of it's wrote in markup. It's not server control.

    But I can be wrong
  10. #10
    You are right, I meant the DynamicControl.ascx, but there is no DirectMethods. Actually, too many things you posted.

    For example, I don't think the Master Page is required to reproduce it. I think a single ASPX and a single ASCX would be enough.

    Please always try to simplify code samples as much as you can. This technique can help.
    How to prepare a sample

    Also please always provide more details about the error. When I run your code sample, I am getting this error:

    SyntaxError: missing ; before statement
    ...ontentPlaceHolder1_ctl02_dynamicControl tab1_txt.setValue("dynamicControl tab1")
    Is this the problem?

    It lays here:
    dc.ID = "dynamicControl " + panel.ID;
    Please do not use spaces in IDs.

    The same is here:
    dynamicControl.ID = "dynamic Control in " + panel.ID;
    Last edited by Daniil; Oct 02, 2012 at 6:06 PM.

Similar Threads

  1. dynamic load usercontrol in ext:pannel.
    By PrasadJoshi in forum 1.x Help
    Replies: 5
    Last Post: Jan 17, 2011, 9:54 AM
  2. Replies: 5
    Last Post: Oct 22, 2010, 10:27 AM
  3. [CLOSED] DirectMethod and UserControl
    By jmcantrell in forum 1.x Premium Help
    Replies: 4
    Last Post: Jun 21, 2010, 7:15 PM
  4. Replies: 4
    Last Post: Feb 25, 2010, 9:33 AM
  5. [CLOSED] XRender UserControl DirectMethod
    By amitpareek in forum 1.x Premium Help
    Replies: 10
    Last Post: Jan 22, 2010, 1:03 PM

Tags for this Thread

Posting Permissions