zoukankan      html  css  js  c++  java
  • 请教各位一个关于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后的视图状态捉摸不清。

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

  • 相关阅读:
    windows cmd中查看某个命令所在的路径
    linux vi编辑器中,如何通过快捷键上下翻页?
    linux系统中,查看当前系统中,都在监听哪些端口
    下载mysql server安装包的时候,不登录oracle账号,实现下载
    plsql developer中,清除登录历史
    linux环境下,清空history中记录的历史命令
    Linux下搭建hadoop开发环境-超详细
    HDFS架构详解-非官档
    SSH免密码登录配置方法详解
    bin/hdfs dfs命令存在WARN util.NativeCodeLoader问题消除方法
  • 原文地址:https://www.cnblogs.com/McJeremy/p/1450819.html
Copyright © 2011-2022 走看看