Cannot get Text from TextField

  1. #1

    Cannot get Text from TextField

    Please help, I have a simple example:

    <ext:ResourceManager runat="server" />
        <ext:Viewport runat="server">
            <Items>  <ext:TextField runat="server" ID="Txt1" FieldLabel="Insert"/>
                     <ext:TextArea runat="server" ID="Area1" FieldLabel="Text" />
                     <ext:Button runat="server" ID="Btn1" Text="Click" UI="Primary"  OnDirectClick="Do"></ext:Button>
                     <ext:Button runat="server" ID="Button1" Text="Click" UI="Primary"  OnDirectClick="getText"></ext:Button>
            </Items>
        </ext:Viewport>
    and in code behind I have the following:

    protected void Do(object sender, EventArgs e)
    {
        string b = Txt1.Text.ToString();
        string c = Area1.Text;
    }
    Nor string neither c save the value from the text field, how can I obtain it if it is entered by the user and after clicking the button ? Please help, I am desperate...
    Last edited by geoffrey.mcgill; Aug 10, 2015 at 5:35 PM.
  2. #2
    Hello @faridhajnal! Welcome to Ext.NET forums!

    This does not work because the code behind does not have control over page contents once the page has already sent to the client.

    In order to be able to fetch what's on the page during an AJAX call (direct method/event like you are doing), you have to actually pass these arguments.

    Look at this example: DirectMethod Overview

    The third case shown in the example illustrates what you likely need, passing a form values to a code behind method:
    <script runat="server">
        [DirectMethod]
        public void LogCompanyInfo(string name, int count)
        {
            string template = string.Concat("{0} has approximately {1} employees.");
            string[] employees = new string[4] { "1-5", "6-25", "26-100", "100+" };
            
            this.Label3.Text = string.Format(template, name, employees[count]);
        }
    </script>
    
    <ext:Button runat="server" Text="Submit">
        <Listeners>
            <Click Handler="App.direct.LogCompanyInfo('Ext.NET, Inc.', 0);" />
        </Listeners>
    </ext:Button>
    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    thank you very much for your answer !

Similar Threads

  1. textfield text error
    By maxdiable in forum 2.x Help
    Replies: 1
    Last Post: Aug 27, 2013, 12:53 PM
  2. Replies: 5
    Last Post: Aug 16, 2013, 2:40 PM
  3. ext:TextField text wrap please help
    By gopikrishna in forum 1.x Help
    Replies: 0
    Last Post: Feb 14, 2011, 7:50 AM
  4. [CLOSED] Cannot set the text in a TextField
    By iansriley in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 12, 2010, 4:34 PM
  5. TextField text disappearing
    By EzaBlade in forum 1.x Help
    Replies: 8
    Last Post: Apr 24, 2009, 7:46 AM

Posting Permissions