先上代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>無標題頁</title>
</head>
<body>
<script type="text/javascript" language="javascript">
function doo()
{
//javascript修改值和CodeBehinds中修改的效果一致?
document.getElementById('inputText').value="asdf";
document.form1.submit();
}
</script>
<form id="form1" runat="server">
<div>
<asp:FileUpload id="fileUpload" runat="server" />
<br />
inputText1:<input type="text" id="inputText1" name="inputText1" runat="server" maxlength="12" />
<br />
inputText:<input type="text" enableviewstate="false" id="inputText" name="inputText" runat="server" maxlength="12" />
<br />
<input type="button" id="btnAdd" name="btnAdd" runat="server" onclick="doo()" value="添加" />
</div>
</form>
</body>
</html>
---CodeBehinds
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_PreLoad(object sender,EventArgs e)
{ //已經將inputText的enableSessionState設為false,這裡為什麼還可以擷取到它的值?
inputText1.Value = inputText.Value;
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(this.IsPostBack.ToString()+"<br />");
Response.Write(inputText.Value);
inputText.Value = "xu test";
}
}
---疑問如下:
1、通過JavaScript是否可以修改HtmlControls(HtmlInputText)的Value屬性值?
2、如果可以通過JavaScript修改,那麼該修改是否會改變該控制項檢視狀態值(ViewState)?
3、如果可以改檢視狀態值,那麼為什麼我將 inputText 的enablesessionstate設為false後,
在Page_PreLoad中仍然可以擷取到inputText的Value,按理說應該是為空白或null的?
4、是否EnableSessionState不適用於HtmlControls?如果是的話,那我在JavaScript中修改inputText的Value屬性值後
經過PostBack後,仍然可以擷取到修改後的值,是通過什麼原理實現的?
----
一直對PostBack後的檢視狀態捉摸不清。
希望各位園友能幫兄弟解惑解惑。。。十分感謝。