Setting the TextField ReadOnly property to toggle on click of Button

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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;
                this.TextField1.ReadOnly = false;
            if (this.TextField1.Disabled == true)
                this.TextField1.Disabled = false;
                this.TextField1.Disabled = true;
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <head runat="server">
        <form id="form1" runat="server">
        <ext:resourcemanager runat="server" />
            <ext:textfield id="TextField1" runat="server" text="I'm read only" />
            <ext:button runat="server" text="Set up ReadOnly to false" ondirectclick="SetReadOnlyFalse" />
    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

    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.


    <ext:button runat="server" text="Set up ReadOnly to false">
            <Click OnEvent="SetReadOnlyFalse" ViewStateMode="Enabled" />
    Hope this helps.
    Geoffrey McGill
    Founder & CEO
  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. 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 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