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

Page 1 of 2 12 LastLast
  1. #1

    [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.
    [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
    Hi vali1993,

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

    Could you provide an example reproducing the issue?

    Example
    <%@ 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>
  3. #3
    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.

    <%@ 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>
    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
    sorry posted the wrong directmethod in the previous code example. here it is again.

     
    [DirectMethod]
    public void GetReport()
    { 
    string x;
    x=X.GetCmp<TextField>("DateField2").Text;
    }
  5. #5
    Hi,

    Seems it also works fine.

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

    Example
    <%@ 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>
  6. #6
    Here's a slightly modified version of the sample.

    Example

    <%@ 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
    Founder
  7. #7
    Thanks.
    tried the example. date returns {1/1/0001 12:00:00 AM}, for TextField, still returns "" :(:confused:
  8. #8
    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
    Founder
  9. #9
    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.
  10. #10
    latest version 1.0.3924.25569. (is this the right version?) still not showing value.
    <%@ 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>
Page 1 of 2 12 LastLast

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 Legacy 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 Legacy 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