Search

ReadOnly Controls do not post back properly when EnableViewState is false on Page by rstrahl

Closed
as Won't Fix Help for as Won't Fix

10
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 102065
Opened: 12/20/2005 3:16:09 PM
Access Restriction: Public
5
Workaround(s)
5
User(s) can reproduce this bug
If you have a control on a page that is marked Read-Only and EnableViewState is set to false on the Page, the ReadOnly value will no longer post back in ASP.NET 2.0 - the value gets lost. This even though the value is actually returned in the POST buffer.

This behavior is also different than 1.1 which (correctly I say) posted back the READONLY value.
Details (expand)
Product Language
English
Version
Visual Studio 2005
Category
Compatibility
Operating System
Windows Server 2003
Operating System Language
US English
Steps to Reproduce
<%@ Page language="c#" enableviewstate="false" Trace="true" %>
<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Textbox1.Text = "readonly text";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.lblMessage.Text = this.Textbox1.Text;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body>
<form runat="server" id="Form1">
<asp:textbox ID="Textbox1" runat="server" ReadOnly="true" ForeColor="silver"></asp:textbox>
<asp:textbox ID="Textbox2" runat="server" ReadOnly="true">Some Text</asp:textbox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
<asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>

Run the page above in 2.0 and 1.x.

Actual Results
2.0:
Page loads with the value showing as readonly. When you click the button the value the first textbox gets lost.

1.1
Page loads with the value showing as readonly. When you click the button the value properly is posted back.
Expected Results
Same behavior as V1.1.

Workaround:
Have to explicitly call Request.Form[TextBox1.UniqueID"] to assign text.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 12/21/2005 at 9:02 PM
Thank you for your feedback. We are investigating this issue.

Thank you, VS2005 Product Team.
Posted by Microsoft on 1/23/2006 at 10:14 AM
Thank you for your concern regarding the value of textbox when the viewstate is disabled.

After careful analysis, the explanation for the observed behaviour is that:
With a design change in ASP .NET based on user security concern, the input for a readonly textbox is saved in viewstate, which doesnt happen if viewstate is disabled. To workaround this, a page developer can add the readonly attribute to the TextBox.Attributes collection, which can then be used to access the 'value' of the textbox.

We hope this clarifies. Thank you.
Web Server & Tools
Posted by Sweizone on 12/30/2008 at 11:12 PM
Is there any work around for a label (server control) which is populated by javascript using innerText. Cause label looses its value on postback.