Tag Archives: ReadonlyTextbox readonly textbox postbackissuewithtextboxreadonly asp.net2.0

Readonly Textbox Postback Issue in ASP.Net v2.0

Just discovered, if the Textbox has readonly property set to true in the design mode, postback won’t load the data back into the textbox in order to prevent the malicious user from changing text value that is read-only.

But it happens sometimes you don’t want to let user type in in the textbox like Date of birth. The alternative to that is as follows:

In the code behind on the page_load event add the following line.

if (!Page.IsPostBack)
{

txtDate.Attributes.Add(“readonly”, “readonly”);
}

This will do the trick and you can use the readonly textbox easily without losing value at the postback and let the use select the date using calender control.

Advertisements
Tagged