I checked the following information online:
In the previous ASP. net 1. in Version X, after the value of the Textbox Control set to readonly is changed on the client side, the modified value can still be obtained on the server side, but in ASP.. NET 2.0. This is to improve application security. The following is the internal method for the Textbox Control to obtain data. We can see the readonly restriction:
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;
}
This only limits the text attribute, but does not limit the namevaluecollection of the name/value of the submitted data. Therefore, you can still obtain the value through the request ["form name"] method. The following example fully demonstrates this and provides methods for obtaining values using both readonly and text attributes:
<% @ Page Language = "C #" enableviewstate = "false" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<SCRIPT runat = "server">
Protected void button#click (Object sender, eventargs E)
{
Response. Write ("<li> textbox1 =" + textbox1.text );
Response. Write ("<li> textbox2 =" + textbox2.text );
Response. Write ("<li> textbox3 =" + textbox3.text );
Response. Write ("<li> request. Form [textbox1] =" + request. Form [textbox1.uniqueid]);
Response. Write ("<li> request. Form [textbox2] =" + request. Form [textbox2.uniqueid]);
Response. Write ("<li> request. Form [textbox3] =" + request. Form [textbox3.uniqueid]);
}
Protected void page_load (Object sender, eventargs E)
{
Textbox3.attributes. Add ("readonly", "readonly ");
}
</SCRIPT>
<SCRIPT type = "text/JavaScript">
// <! [CDATA [
Function setnewvalue ()
{
Document. getelementbyid (''<% = textbox1.clientid %>''). value = "textbox1 new value ";
Document. getelementbyid (''<% = textbox2.clientid %>''). value = "textbox2 new value ";
Document. getelementbyid (''<% = textbox3.clientid %>''). value = "textbox3 new value ";
}
//]>
</SCRIPT>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Textbox Control and readonly and enabled attributes in ASP. NET 2.0 </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Span> textbox1 readonly: </span>
<Asp: textbox id = "textbox1" runat = "server" readonly = "true" text = "textbox1 old value"> </ASP: textbox> <br/>
<Span> textbox2 enabled: </span>
<Asp: textbox id = "textbox2" runat = "server" enabled = "false" text = "textbox2 old value"> </ASP: textbox> <br/>
<Span> textbox3 readonly: </span>
<Asp: textbox id = "textbox3" runat = "server" text = "textbox3 old value"> </ASP: textbox> <br/>
<Br/>
<Asp: button id = "button2" runat = "server" text = "Modify new value" onclientclick = "setnewvalue (); Return false;"/>
<Asp: button id = "button1" runat = "server" text = "Submit" onclick = "button#click"/>
</Form>
</Body>
</Html>
For the textbox of disabled, the modification value cannot be obtained on the server side. If you want to use this attribute, you can use the method to hide the form field.
The textbox of the readonly attribute will display such a mark on the client:
<Input readonly = "readonly">
The textbox of the enabled attribute will present such a flag on the client:
<Input Disabled = "disabled">
Per W3C specification: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.12
If the input parameter is set to disabled, the following restrictions apply:
Cannot receive focus
The tab key is skipped.
It may not be successful's
The following restrictions apply to input with readonly:
Can receive the focus but cannot be modified
You can use the tab key for navigation.
It may be successful's
Only the form element of successful is valid data, that is, it can be submitted. The disabled and readonly text input boxes can only be modified using scripts.
Conclusion:
In other words, you can use a script to modify the value on the foreground. However, only the textbox that dynamically adds the readonly attribute can use JS on the foreground to obtain the modified value (because it is not parsed ), the textbox set to the readonly attribute can use reqest in the background after the starting value is modified. forms [] method to obtain its value, but the value set to disable cannot be modified on the server. The original values of the three controls can be obtained through JS on the page.