请教各位一个关于HtmlControls与JavaScript的疑问

先上代码:

<%@ 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后的视图状态捉摸不清。

  希望各位园友能帮兄弟解惑解惑。。。十分感谢。

posted @ 2009-05-06 17:17  mcjeremy  阅读(339)  评论(1编辑  收藏  举报
------------------------------------ 心静似高山流水不动,心清若巫峰雾气不沾 ------------------------------------