[Source: appdev-sysk 118] Sometimes, we do not want users to edit textbox directly, but want to set it through client scripts.
The general practice is to set the textbox attribute readonly to true. But there is a change in ASP. NET 2.0, and readonly is set to true.
The textbox on the server side cannot obtain the new content set on the client through the text attribute. In reflector, compare the content of loadpostdata
Implementation
In. NET 1.1,
Bool ipostbackdatahandler. loadpostdata (string postdatakey, namevaluecollection postcollection)
{
String text1 = This. text;
String text2 = postcollection [postdatakey];
If (! Text1.equals (text2 ))
{
This. Text = text2;
Return true;
}
Return false;
}
In. NET 2.0,
Protected virtual bool loadpostdata (string postdatakey, namevaluecollection postcollection)
{
Base. validateevent (postdatakey );
String text1 = This. text;
String text2 = postcollection [postdatakey];
If (! This. readonly &&! Text1.equals (text2, stringcomparison. ordinal ))
{
This. Text = text2;
Return true;
}
Return false;
}
We can see that if readonly is set to true, the new value returned from the client is not set to the text attribute.
To maintain the behavior in. Net 1. *, we recommend that you set the client property contenteditable = false. For more information, see
Syskey 118: readonly or contenteditable?
Http://blogs.msdn.com/irenak/archive/2006/05/03/589085.aspx
In fact, if you set the client properties, you can also set the readonly attribute of the client:
Textbox1.attributes ["readonly"] = "true ";
Example:
Txtcol_rr_rt_area.attributes [ " Contenteditable " ] = " False " ;
Txtcol_rr_rt_quality.attributes [ " Contenteditable " ] = " False " ;
Foreach (Gridviewrow gvr In Gridview1.rows)
{
(Textbox) gvr. findcontrol ( " Txtquality " ). Attributes [ " Readonly " ] = " True " ;
(Textbox) gvr. findcontrol ( " Txtarea " ). Attributes [ " Readonly " ] = " True " ;
}