Setting the TextField ReadOnly property to toggle on click of Button

  1. #1

    Setting the TextField ReadOnly property to toggle on click of Button

    I want a toggle button to set the textfield readonly property to set to false and true on click of button at server side.
    But the TextField1.ReadOnly property always shows false on server side.
    The below code doesn't work.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReadOnlyPropertyTestForm1.aspx.cs"
        Inherits="CooliteTestApplication1.ReadOnlyPropertyTestForm1" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void SetReadOnlyFalse(object sender, DirectEventArgs e)
        {
            this.TextField1.Text = "I'm editable";
            if (this.TextField1.ReadOnly == false)
            {
                this.TextField1.ReadOnly = true;
            }
            else
            {
                this.TextField1.ReadOnly = false;
            }
    
            if (this.TextField1.Disabled == true)
            {
                this.TextField1.Disabled = false;
            }
            else
            {
                this.TextField1.Disabled = true;
            }
        }
            
    </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 runat="server" />
        <div>
            <ext:textfield id="TextField1" runat="server" text="I'm read only" />
            <ext:button runat="server" text="Set up ReadOnly to false" ondirectclick="SetReadOnlyFalse" />
        </div>
        </form>
    </body>
    </html>
    Any help is highly appreciated. thx in advance
    Last edited by geoffrey.mcgill; Dec 20, 2011 at 2:30 AM. Reason: please use [CODE] tags
  2. #2
    Hi,

    By default, ViewState is not sent in a DirectEvent request. You can override this behaviour by setting ViewStateMode="Enabled" on the DirectEvent config.

    The following sample should make your other code work as expected.

    Example

    <ext:button runat="server" text="Set up ReadOnly to false">
        <DirectEvents>
            <Click OnEvent="SetReadOnlyFalse" ViewStateMode="Enabled" />
        </DirectEvents>
    </ext:button>
    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3
    Thanks Geoffrey, that solved my problem. You can mark as solved.

Similar Threads

  1. Replies: 4
    Last Post: Jan 04, 2012, 4:38 AM
  2. [CLOSED] How toggle button keep active even after click on it
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 01, 2012, 4:54 PM
  3. Replies: 1
    Last Post: Oct 12, 2010, 8:39 PM
  4. [CLOSED] Textfield Readonly Property
    By speedstepmem2 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 24, 2009, 11:52 AM
  5. Replies: 1
    Last Post: Nov 21, 2008, 7:10 AM

Tags for this Thread

Posting Permissions