But it looks like the enabled property is not saved. For instance, I
have a page with a checkbox, a textbox and a button on it. When a user
clicks the checkbox off, a javascript function is executed that disables
the textbox. When a user clicks the button, the page is submitted and
the user is returned to the page.
Here's the user test scenario I used: I change the value contained
within the textbox, I click off the checkbox, disabling the text box. I
click submit.
What I expect to see when the page is brought back is an unchecked
checkbox and a disabled textbox with the changed text in it. What I
actually get is an unchecked checkbox and an ENABLED textbox with the
original text in it. It looks like the enabled property is not saved on
a control and, if a control is disabled, all other properties are not
saved.
Here's my aspx file:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="ControlProperties.aspx.vb"
Inherits="Sandbox.Web.ControlProperties"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>ControlProperties</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
<!--
function EnableDisableTextBox(){
var lTextBox = document.getElementById("TxtTextBox");
lTextBox.disabled = !(lTextBox.disabled);
}
//-->
</script>
</head>
<body MS_POSITIONING="GridLayout">
<form id="MyForm" method="post" runat="server">
<asp:checkbox ID="ChkCheckBox" onclick="EnableDisableTextBox();"
runat="server"
EnableViewState="true"/> <asp:textbox
ID="TxtTextBox" Text="This is some text" Runat="server"
EnableViewState="true"/>
<asp:button ID="BtnSubmit" text="Submit" Runat="server"/>
</form>
</body>
</html>
Here's my aspx.vb file:
Public Class ControlProperties
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by
the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Protected WithEvents ChkCheckBox As
System.Web.UI.WebControls.CheckBox
Protected WithEvents TxtTextBox As
System.Web.UI.WebControls.TextBox
Protected WithEvents BtnSubmit As
System.Web.UI.WebControls.Button
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub BtnSubmit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BtnSubmit.Click
End Sub
End Class
Is there any way to change this behaviour so that I can save the enabled
property in the view state, as well as maintain the other properties in
the viewstate if the enabled property is set to false?
Thanks,
Leo Hart