[CLOSED] UserControlLoader getValue from DirectMethod

  1. #1

    [CLOSED] UserControlLoader getValue from DirectMethod

    I want to set [DirectMethod] strA() in a.aspx to txtb in b.ascx
    I don't know Button1_Click content in a.aspx
    I don't know how to get strA() from a.aspx in b.ascx

    pls help me, thanks very much.

    a.aspx
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
    
        protected void Page_Init(object sender, EventArgs e)
        {
            UserControlLoader ul1 = new UserControlLoader();
            ul1.ID = "uc1";
            ul1.Path = "b.ascx";
            Panel1.Items.Add(ul1);
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack && !X.IsAjaxRequest)
            {
    
            }
        }
    
        [DirectMethod]
        public string strA()
        {
            string str1 = "a-Value" + DateTime.Today.AddMonths(-1).ToString("yyyy-MM-dd");
            return str1;
        }
    
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            UserControlLoader ul1 = X.GetCmp<UserControlLoader>("uc1");
            ul1.Render(); //??? I dont know how to refresh
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Panel
                ID="Panel1"
                runat="server"
                Title="Panel"
                Height="150"
                 Width ="280">
                <Items>
    
                    <ext:Button runat="server" Text="Set DirectMethod-Value to txtB" OnDirectClick="Button1_Click"  ID ="Button1"/>
                    
                </Items>
            </ext:Panel>
        </form>
    </body>
    </html>
    b.ascx
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <ext:TextField ID="txtb" runat="server" FieldLabel="txtB" LabelWidth="25" />
    
    <script type="text/javascript">
        var str2 = '';
        //str2 = parent.App.direct.strA(); //// ??? I dont know how  to get strA() from a.aspx
        App.txtb.setValue(str2);
    </script>
    Last edited by Daniil; Oct 11, 2014 at 6:43 AM. Reason: [CLOSED]
  2. #2
    Hi @CPA1158139,

    You could do the following in the user control.

    Example
    <ext:TextField 
        ID="txtb" 
        runat="server" 
        FieldLabel="txtB" 
        LabelWidth="25">
        <Listeners>
            <Render Handler="var field = this; 
                             App.direct.strA({
                                 success: function(result) {
                                     field.setValue(result);
                                 }
                             });" />
        </Listeners>
    </ext:TextField>
    As for refreshing a UserControlLoader, I would wrap it in an additional Container:
    <ext:Container ID="Container1" runat="server" />
    Container1.Items.Add(ul1);
    and call
    this.Container1.UpdateContent();
    But it is not working. Probably, a defect in Ext.NET. We will try to fix.

    As a solution you can do the following.

    1. Place this into the Panel1's Items.
    <ext:Container ID="Container1" runat="server" Layout="AnchorLayout" />
    2. Use these methods:
    protected void Page_Init(object sender, EventArgs e)
    {
        this.Container1.ContentControls.Add(this.LoadControl("TestUC.ascx"));
    }
    protected void Button1_Click(object sender, DirectEventArgs e)
    {
        this.Container1.UpdateContent();
    }
  3. #3
    It works fine.Thanks very much!

    Sorry, by the way,how to getValue without TextField? I get a error msg


    b.ascx
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script type="text/javascript"> 
            App.direct.strA({
                success: function (result) {
                    alert(result);
                }
            });
       
    </script>
  4. #4
    I get a error msg
    Please always post the error and Exception messages.

    I guess there is something like "App.direct is undefined".

    It means that the script executes too early, before creating of the App.direct namespace.

    You can use:
    <script>
        Ext.onReady(function() {
            App.direct.strA({
                success: function(result) {
                    alert(result);
                }
            });
        });
    </script>
  5. #5
    Sure,Daniil,you are great.
    I understand Ext.onReady is used to initialize. How to render?
  6. #6
    How to render?
    How to render what? Can you provide some more details, or an updated sample demonstrating the scenario you are attempting to get working.
    Geoffrey McGill
    Founder
  7. #7
    I understand there is a mistake. No problem.
    pls close.
    thanks very much.
  8. #8
    ...and call
    this.Container1.UpdateContent();
    But it is not working. Probably, a defect in Ext.NET. We will try to fix.
    It has been fixed in the revision #6021.

Similar Threads

  1. Replies: 4
    Last Post: Sep 27, 2013, 12:09 PM
  2. getValue problem in js
    By samsaertug in forum 2.x Help
    Replies: 1
    Last Post: Mar 26, 2013, 11:00 PM
  3. [CLOSED] App.txtUserName.getValue()
    By imaa in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 23, 2013, 9:26 AM
  4. [CLOSED] Combobox getValue
    By jthompson in forum 1.x Legacy Premium Help
    Replies: 25
    Last Post: Jun 15, 2012, 11:14 AM
  5. Format datefield getValue
    By Tbaseflug in forum 1.x Help
    Replies: 1
    Last Post: Oct 21, 2011, 1:23 AM

Posting Permissions