请教各位一个关于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()
ExpandedBlockStart.gifContractedBlock.gif 
{   

    //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 
ExpandedBlockStart.gifContractedBlock.gif
{
    
protected void Page_PreLoad(object sender,EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{        //已经将inputText的enableSessionState设为false,这里为什么还可以获取到它的值?
        inputText1.Value 
= inputText.Value;
    }

    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        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后的视图状态捉摸不清。

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

转载于:https://www.cnblogs.com/McJeremy/archive/2009/05/06/1450819.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值