国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

asp.net 2.0里當readonly遇上enableviewstate=false

2019-11-18 19:01:58
字體:
來源:轉載
供稿:網友

偶然在一個老外的blog里看到有這樣的描述,當textbox控件里被設置為readonly時,而且頁面的enableviewsate設置為false時,提交后,textbox的值會丟失,這只發生在asp.net 2.0中,在asp.net 1.0/1.1中不會出現這樣的情況,代碼如下:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" EnableViewState="false"  Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<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="<head runat="server">
    <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>
在.net 2.0下運行,的確會丟失了文本框的值。最后,找到了MSDN的解析和微軟的BUG反饋中心,其實這不是BUG,是.net 2.0下為了安全的一個小改變,具體摘錄如下,大家就明白了:
微軟的反饋為:
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

 

MSDN 2005的解析:


The Text value of a TextBox control with the ReadOnly property set to true is sent to the server when a postback occurs, but the server does no processing for a read-only text box. This prevents a malicious user from changing a Text value that is read-only. The value of the Text property is preserved in the view state between postbacks unless modified by server-side code.


出處:jackyrong blog


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 延寿县| 德令哈市| 武宣县| 乌海市| 息烽县| 镇平县| 霞浦县| 平陆县| 武强县| 天津市| 邵武市| 濮阳县| 临泉县| 金湖县| 康保县| 马山县| 阿拉善左旗| 长岭县| 桂平市| 正安县| 弥渡县| 马鞍山市| 格尔木市| 漾濞| 苏尼特右旗| 新巴尔虎右旗| 新化县| 景泰县| 桦甸市| 专栏| 周至县| 彭山县| 海口市| 饶河县| 门源| 鄂伦春自治旗| 红安县| 张家界市| 桃江县| 台湾省| 建宁县|