首页 新闻 会员 周边

请教一下关于HtmlControls与JavaScript的一个疑问。

0
悬赏园豆:10 [已关闭问题]

先上代码:

<%@ 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后,仍然可以获取到修改后的值,是通过什么原理实现的?

mcjeremy的主页 mcjeremy | 初学一级 | 园豆:6
提问于:2009-05-06 17:18
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册