Lost label value in Blur Event of TextField

  1. #1

    Lost label value in Blur Event of TextField

    Hi, please look my example. When select combobox --> set label value to "AAAAAA". But when Blur event of TextField fired, label value is empty.

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        protected void amountTextBox_Blur(object sender, Ext.Net.DirectEventArgs e)
        {
            string b33Str = this.b33Label.Text.Trim();
            this.textField1.Text = b33Str;
        }
    
        protected void Drop_Selected(object sender, Ext.Net.DirectEventArgs e)
        {
            this.b33Label.Text = "AAAAAAAAAAAAAAAAAAA";
        }
    </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></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" DirectMethodNamespace="MainSiteForm" />
        <div>
            <ext:ComboBox ID="Drop" runat="server">
                <Items>
                    <ext:ListItem Value="0" Text="Option1">
                    </ext:ListItem>
                </Items>
                <DirectEvents>
                    <Select OnEvent="Drop_Selected">
                    </Select>
                </DirectEvents>
            </ext:ComboBox>
            <ext:Label ID="b33Label" runat="server">
            </ext:Label>
            <ext:TextField Text="Common" ID="textField1" runat="server">
                <DirectEvents>
                    <Blur OnEvent="amountTextBox_Blur">
                        <EventMask ShowMask="true" Target="Page" />
                    </Blur>
                </DirectEvents>
            </ext:TextField>
        </div>
        </form>
    </body>
    </html>
  2. #2
    I cleaned up your original sample for you.

    Example

    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <script runat="server">
        protected void TextField1_Blur(object sender, Ext.Net.DirectEventArgs e)
        {
            string lbl = this.Label1.Text.Trim();
            this.TextField1.Text = lbl;
        }
     
        protected void Drop_Selected(object sender, Ext.Net.DirectEventArgs e)
        {
            this.Label1.Text = "AAAAAAAAAAAAAAAAAAA";
        }
    </script>
    
    
    <!DOCTYPE html>
    
    
    <html>
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <ext:ComboBox runat="server">
                <Items>
                    <ext:ListItem Value="0" Text="Option1" />
                </Items>
                <DirectEvents>
                    <Select OnEvent="Drop_Selected" />
                </DirectEvents>
            </ext:ComboBox>
    
    
            <ext:Label ID="Label1" runat="server" />
            
            <ext:TextField ID="TextField1" Text="Common" runat="server">
                <DirectEvents>
                    <Blur OnEvent="TextField1_Blur" />
                </DirectEvents>
            </ext:TextField>
        </form>
    </body>
    </html>
    Geoffrey McGill
    Founder
  3. #3
    The problem here is that you are relying on ViewState to persist this value for you across requests. By default, in Ext.NET ViewState is disabled. So, you either have to enable ViewState, or use a different technique for persisting information across requests.

    You can set ViewStateMode="Enabled" on any DirectEvent configuration object.

    Example

    <ext:ComboBox runat="server">    <Items>
            <ext:ListItem Value="0" Text="Option1" />
        </Items>
        <DirectEvents>
            <Select OnEvent="Drop_Selected" ViewStateMode="Enabled" />
        </DirectEvents>
    </ext:ComboBox>
    
    
    <ext:Label ID="Label1" runat="server" />
            
    <ext:TextField ID="TextField1" Text="Common" runat="server">
        <DirectEvents>
            <Blur OnEvent="TextField1_Blur" ViewStateMode="Enabled" />
        </DirectEvents>
    </ext:TextField>
    Or, you could add a value as a Parameter of the DirectEvent request. Or, store the value in a HiddenField which will be submitted back to the server.

    Hope this helps.
    Geoffrey McGill
    Founder
  4. #4
    Quote Originally Posted by geoffrey.mcgill View Post
    The problem here is that you are relying on ViewState to persist this value for you across requests. By default, in Ext.NET ViewState is disabled. So, you either have to enable ViewState, or use a different technique for persisting information across requests.

    You can set ViewStateMode="Enabled" on any DirectEvent configuration object.

    Example

    <ext:ComboBox runat="server">    <Items>
            <ext:ListItem Value="0" Text="Option1" />
        </Items>
        <DirectEvents>
            <Select OnEvent="Drop_Selected" ViewStateMode="Enabled" />
        </DirectEvents>
    </ext:ComboBox>
    
    
    <ext:Label ID="Label1" runat="server" />
            
    <ext:TextField ID="TextField1" Text="Common" runat="server">
        <DirectEvents>
            <Blur OnEvent="TextField1_Blur" ViewStateMode="Enabled" />
        </DirectEvents>
    </ext:TextField>
    Or, you could add a value as a Parameter of the DirectEvent request. Or, store the value in a HiddenField which will be submitted back to the server.

    Hope this helps.

    Thank for your reply. I tried ViewStateMode option but still not work, option hiddenField is OK. Can i use Page Session ?
  5. #5
    Quote Originally Posted by GolineTidus View Post
    I tried ViewStateMode option but still not work, option hiddenField is OK.
    That's probably a good thing. You should not be using ViewState... ever.

    Can i use Page Session ?
    Yes, Session will work, although passing the value as a Parameter of the request is the method we would recommend. HiddenField is not as clean, but would be ok too.
    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] TextField: Help with Remove SelectedText on Blur event
    By nhg_itd in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 31, 2012, 1:12 AM
  2. [CLOSED] TextField Blur event is throwing error in Editable Grid
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 05, 2012, 4:25 PM
  3. TextField DirectEvent Blur Error
    By David Pelaez in forum 1.x Help
    Replies: 5
    Last Post: Dec 21, 2010, 12:32 PM
  4. send extra parameters on blur event of textfield editor inside gridpanel
    By aditya.murthy88@gmail.com in forum 1.x Help
    Replies: 2
    Last Post: Dec 11, 2010, 12:04 PM
  5. [CLOSED] validate textfield on blur
    By idrissb in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 29, 2009, 3:47 PM

Posting Permissions