Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: [CLOSED] get value of controls created in code-behind

  1. #1
    Member
    Join Date
    Jan 2010
    Posts
    177

    [CLOSED] get value of controls created in code-behind

    I successfully create controls based on the replies from http://forums.ext.net/showthread.php...in-code-behind
    But I am unable to get value from those controls by clicking a button. The controls is found, but value returns "". could you please advice how i can get values of those dynamically created controls? Thank you.
    Code:
    [DirectMethod]
    publicvoid GetResult()
    { 
    string x;
    x = X.GetCmp<DateField>("DateField2").Text;
    }
    Last edited by Daniil; Sep 30, 2010 at 7:59 AM. Reason: [CLOSED]

  2. #2
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,203
    Hi vali1993,

    Seems it works fine. Please look at the example below.

    Could you provide an example reproducing the issue?

    Example
    Code:
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            new DateField() {
                ID = "DateField1",
                CustomConfig = {
                    new ConfigItem("value", "10.09.2010", ParameterMode.Value)
                }   
            }.AddTo(this.Form);
        }
    
        [DirectMethod]
        public void GetResult()
        {
            string x;
            x = X.GetCmp<DateField>("DateField1").Text;
            X.Msg.Alert("", x).Show();
        }
    </script>
     
    <!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">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Button runat="server" Text="Get text">
            <Listeners>
                <Click Handler="Ext.net.DirectMethods.GetResult();" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  3. #3
    Member
    Join Date
    Jan 2010
    Posts
    177
    The only thing is different from your example is that the controls are not created in page_load. They are created in DirectEvent.
    Thanks again.

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Reports.aspx.cs" Inherits="Admin_Reports" %>
    <%@ 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">
    <title>Untitled Page</title>
    </head>
    <body>
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>
    <ext:Button ID="btnTest" runat="server" Text="Dynamically Generate Controls">
    <DirectEvents>
    <Click OnEvent="CreateFilterForm">
    </Click>
    </DirectEvents>
    </ext:Button>
    <ext:Window ID="winFilter" runat="server" Title="Report" Icon="Magnifier" Closable="True"
    Width="300" Height="250" Resizable="false" BodyStyle="background-color:#fff;"
    Hidden="true" AutoShow="false" AutoRender="false" Modal="true" Layout="Form">
    <Items>
    </Items>
    <BottomBar>
    <ext:Toolbar ID="Toolbar1" runat="server">
    <Items>
    <ext:Button ID="btnGetReport" runat="server" Text="Get Report" Icon="ReportStart">
    <Listeners>
    <Click Handler="Ext.net.DirectMethods.GetReport()" />
    </Listeners>
    </ext:Button>
    <ext:Button ID="btnCancel" runat="server" Text="Cancel">
    <Listeners>
    <Click Handler="FormPanel1.destroy();winFilter.hide()"></Click>
    </Listeners>
    </ext:Button>
    </Items>
    </ext:Toolbar>
    </BottomBar>
    </ext:Window>
    </body>
    </html>
    Code:
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using Ext.Net;
    public partial class Admin_Reports : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void CreateFilterForm(object sender, DirectEventArgs e)
    {
    new FormPanel
    {
    ID = "FormPanel1",
    Padding = 5,
    LabelWidth = 120,
    Height = 220
    }.Render(this.winFilter, RenderMode.AddTo);
    
     
    Ext.Net.DateField dt1 = new Ext.Net.DateField()
    {
    ID = "DateField1",
    Vtype = "daterange",
    FieldLabel = "From",
    AnchorHorizontal = "90%",
    };
    
    Ext.Net.DateField dt2 = new Ext.Net.DateField()
    {
    ID = "DateField2",
    Vtype = "daterange",
    FieldLabel = "To",
    AnchorHorizontal = "90%",
    };
    dt1.CustomConfig.Add(new ConfigItem("endDateField", "DateField2", ParameterMode.Value));
    dt1.AddTo(this.Form);
    dt2.CustomConfig.Add(new ConfigItem("startDateField", "DateField1", ParameterMode.Value));
    dt2.AddTo(this.Form);
    winFilter.Show();
    }
     
    [DirectMethod]
    public void GetReport()
    { 
    string x;
    x=X.GetCmp<TextField>("txtPharmacy").Text;
    }
    }

  4. #4
    Member
    Join Date
    Jan 2010
    Posts
    177
    sorry posted the wrong directmethod in the previous code example. here it is again.

    Code:
     
    [DirectMethod]
    public void GetReport()
    { 
    string x;
    x=X.GetCmp<TextField>("DateField2").Text;
    }

  5. #5
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,203
    Hi,

    Seems it also works fine.

    Probably something is missed in your code... I've not found what exacly yet.

    Example
    Code:
    <%@ Page Language="C#" %>
      
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
      
    <script runat="server">
        protected void CreateDateField(object sender, DirectEventArgs e)
        {
            new DateField() {
                ID = "DateField1",
                CustomConfig = {
                    new ConfigItem("value", "10.09.2010", ParameterMode.Value)
                }  
            }.AddTo(this.Form);
        }
     
        [DirectMethod]
        public void GetResult()
        {
            string x;
            x = X.GetCmp<TextField>("DateField1").Text;
            X.Msg.Alert("", x).Show();
        }
    </script>
      
    <!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">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Button runat="server" Text="Create DateField">
            <DirectEvents>
                <Click OnEvent="CreateDateField" />
            </DirectEvents>
        </ext:Button>
        <ext:Button runat="server" Text="Get text">
            <Listeners>
                <Click Handler="Ext.net.DirectMethods.GetResult();" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  6. #6
    Ext.NET - Dev Team geoffrey.mcgill's Avatar
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    8,630
    Here's a slightly modified version of the sample.

    Example

    Code:
    <%@ Page Language="C#" %>
       
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
       
    <script runat="server">
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            new DateField() {
                ID = "DateField1",
                SelectedDate = DateTime.Today
            }.AddTo(this.Form);
        }
      
        [DirectMethod(Namespace = "CompanyX")]
        public void GetValue()
        {
            var date = X.GetCmp<DateField>("DateField1").SelectedDate;
            X.Msg.Alert("", date.ToString("yyyy-MM-dd")).Show();
        }
    </script>
       
    <!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">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <ext:Button runat="server" Text="Create DateField" OnDirectClick="Button1_Click" />
            
            <ext:Button runat="server" Text="Get text">
                <Listeners>
                    <Click Handler="CompanyX.GetValue();" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
    Geoffrey McGill
    Ext.NET, Inc.
    Founder, and Dev Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | @extnet | Jobs

  7. #7
    Member
    Join Date
    Jan 2010
    Posts
    177
    Thanks.
    tried the example. date returns {1/1/0001 12:00:00 AM}, for TextField, still returns "" :(:confused:

  8. #8
    Ext.NET - Dev Team geoffrey.mcgill's Avatar
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    8,630
    Quote Originally Posted by vali1993 View Post
    Thanks.
    tried the example. date returns {1/1/0001 12:00:00 AM}, for TextField, still returns "" :(:confused:
    Please ensure you are using the latest source code from SVN.
    Geoffrey McGill
    Ext.NET, Inc.
    Founder, and Dev Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | @extnet | Jobs

  9. #9
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,203
    If the problem will persist with the latest code please post a sample code which we can run without any change. Just copy/paste/run.

    Like these ones which are posted by me and Geoffrey.
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  10. #10
    Member
    Join Date
    Jan 2010
    Posts
    177
    latest version 1.0.3924.25569. (is this the right version?) still not showing value.
    Code:
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
         
    <script runat="server"> 
        protected void CreateFilterForm(object sender, DirectEventArgs e)
    {
    new FormPanel
    {
    ID = "FormPanel1",
    Padding = 5,
    LabelWidth = 120,
    Height = 220
    }.Render(this.winFilter, RenderMode.AddTo);
    string s = "TextField";
    switch (s)
    { 
    case "TextField":
    new Ext.Net.TextField()
    {
    ID = "txtPharmacy",
    FieldLabel = "Pharmacy",
    }.Render("FormPanel1", RenderMode.AddTo);
    break;
    case "DateRange":
    Ext.Net.DateField dt1 = new Ext.Net.DateField()
    {
    ID = "DateField1",
    Vtype = "daterange",
    FieldLabel = "From",
    AnchorHorizontal = "90%",
    };
    
    Ext.Net.DateField dt2 = new Ext.Net.DateField()
    {
    ID = "DateField2",
    Vtype = "daterange",
    FieldLabel = "To",
    AnchorHorizontal = "90%",
    SelectedDate = DateTime.Today 
    };
    dt1.CustomConfig.Add(new ConfigItem("endDateField", "DateField2", ParameterMode.Value));
    dt1.AddTo("FormPanel1");
    dt2.CustomConfig.Add(new ConfigItem("startDateField", "DateField1", ParameterMode.Value));
    dt2.AddTo("FormPanel1");
    break;
    
    }
    winFilter.Show();
    }
    [DirectMethod(Namespace="CompanyX")]
    public void GetReport()
    {
    var x = X.GetCmp<TextField>("txtPharmacy").Text;
    X.Msg.Alert("", x).Show();
    }
    </script> 
         
    <!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"> 
     </head> 
    <body>
    <ext:ResourceManager ID="ResourceManager1" runat="server">
    </ext:ResourceManager>
    <ext:Button ID="btnTest" runat="server" Text="Dynamically Generate Controls">
    <DirectEvents>
    <Click OnEvent="CreateFilterForm">
    </Click>
    </DirectEvents>
    </ext:Button>
    <ext:Window ID="winFilter" runat="server" Title="Report" Icon="Magnifier" Closable="false"
    Width="300" Height="250" Resizable="false" BodyStyle="background-color:#fff;"
    Hidden="true" AutoShow="false" AutoRender="true" Modal="true" Layout="Form">
    <Items>
    </Items>
    <BottomBar>
    <ext:Toolbar ID="Toolbar1" runat="server">
    <Items>
    <ext:Button ID="btnGetReport" runat="server" Text="Get Report" Icon="ReportStart">
    <Listeners>
    <Click Handler="CompanyX.GetReport()" />
    </Listeners>
    </ext:Button>
    <ext:Button ID="btnCancel" runat="server" Text="Cancel">
    <Listeners>
    <Click Handler="FormPanel1.destroy();winFilter.hide()"></Click>
    </Listeners>
    </ext:Button>
    </Items>
    </ext:Toolbar>
    </BottomBar>
    </ext:Window>
    </body>
    </html>

Similar Threads

  1. Replies: 1
    Last Post: Nov 15, 2011, 4:48 PM
  2. [CLOSED] How to clean up dynamically created controls?
    By jchau in forum 1.x Premium Help
    Replies: 3
    Last Post: Aug 23, 2011, 9:51 AM
  3. [CLOSED] Unable to access dynamically created controls
    By rnachman in forum 1.x Premium Help
    Replies: 1
    Last Post: Apr 07, 2011, 5:49 AM
  4. Replies: 6
    Last Post: Jun 18, 2010, 4:23 PM
  5. Dynamically created controls cookbooks
    By arodier in forum 1.x Help
    Replies: 15
    Last Post: May 07, 2010, 7:12 PM

Posting Permissions