473,418 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

ViewState for Enabled Property on CheckBox/RadioButton Controls

Hello,

I'm hoping someone can help me out.

I was wondering if the Enabled property of a CheckBox or RadioButton
server control is stored in the ViewState. If not, is there some way
to to add this property to ViewState? If needed, I can give you more
info on exactly what I'm trying to do.

Thanks,
Leo Hart
Nov 18 '05 #1
5 9149
information about the state of controls is saved in viewstate.
so say during serverside processing if the control was marked disabled then
during next postback it will know what the state was and unless you change
it.. it will maintain the same.

you can choose to add your own data to viewstate using somthing like

ViewState["myprop1"] = true;

and read it using something like

if(ViewState["myprop1"] != null)
{
bool myProperty = (bool)ViewState["myprop1"];
}

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Leo J. Hart IV" <le******@fmr.com> wrote in message
news:b6**************************@posting.google.c om...
Hello,

I'm hoping someone can help me out.

I was wondering if the Enabled property of a CheckBox or RadioButton
server control is stored in the ViewState. If not, is there some way
to to add this property to ViewState? If needed, I can give you more
info on exactly what I'm trying to do.

Thanks,
Leo Hart

Nov 18 '05 #2
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"/>&nbsp;&nbsp;&nbsp;&nbsp;<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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
The state information of the textbox was the state on serverside and not
clientside
when you used javascript you only disabled it on clientside. the
stateinformation has no idea about it.

if however you set the textbox as disabled from server side then it will be
maintain on everypostback unless you explicitly change it.

onclick >> javascript == client side effect (has no bearing on server side)

instead of using javascript set the checkbox's autopostback to true and
implement checkbox's onclick as serverside event handler. and then set the
textbox to disabled.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Leo J. Hart IV" <le******@fmr.com> wrote in message
news:OD**************@tk2msftngp13.phx.gbl...
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"/>&nbsp;&nbsp;&nbsp;&nbsp;<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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #4
or have a onload javascript which essentially marks the textbox enabled or
not depending on whether checkbox is checked or not

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Leo J. Hart IV" <le******@fmr.com> wrote in message
news:OD**************@tk2msftngp13.phx.gbl...
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"/>&nbsp;&nbsp;&nbsp;&nbsp;<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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5
Thanks for all of your help everyone! I went with the AutoPostBack
approach and that worked perfectly. I actually have another WebForms
question related to this project, but I'll start a new thread for that.

Thanks again,
Leo Hart

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Anderson | last post by:
I'm having trouble persisting viewstate information for webcontrols I've disabled via javascript. I have a group of textboxes that I enable/disable via a checkbox control that invokes a javascript...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
4
by: dm_dal | last post by:
Is there a know issue surrounding the CheckBoxList control and it's viewstate? When my control is created, it's ListItems are checked as needed, but on a postback, they loose their Selected...
1
by: Mick | last post by:
Hi, Dynamically adding Checkbox and GroupRadioButton (extended control http://www.codeproject.com/aspnet/groupradiobuttons.asp) to placeholder. In fact, displaying questions and answers. When...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
0
by: webmaster | last post by:
Hi all, I'm tearing my hair out with this one. I have successfully implemented by own RadioButtonList in order to provide additional functionality and a DIV rather than TABLE-based layout in...
12
by: Nick C | last post by:
Hi How can i reduce the viewstate for my asp.net application. It is getting very large now. What is a good solution? thanks N
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.