zoukankan      html  css  js  c++  java
  • 使用__doPostBack 事件

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {

            //得到TextBox1

            string cname = Request.Form["__EVENTTARGET"];

            //得到TextBox1的Text值

            string cvalue = Request.Form["__EVENTARGUMENT"];

            if (cname != null && cvalue != "")
            {
                this.Label1.Text = "控件名 " + cname + " 控件值 " + cvalue;

            }

        }

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>无标题页</title>

        <script language="javascript" type="text/javascript">

            function submitTextBox1() {

                var txtBox1 = document.getElementById("TextBox1");

                __doPostBack("TextBox1", txtBox1.value);

                return false;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            通过javascript代码提交文本框内容到服务器<br />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
            文本的内容:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
            <asp:Button ID="Button1" runat="server" OnClientClick="return submitTextBox1();"
                Text="doPostBack" />
            <br />
            <%--必须将dropdownList1 的autopostback属性设为 true 才能自动在页面上产生__doPostBack函数

    并且在页面上产生两个隐藏的按钮

    一个名为__EVENTTARGET 另一个名为__EVENTARGUMENT

    第一个的值是触发事件的控件名

    第二个的值是所带的参数--%>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Width="0px">
            </asp:DropDownList>
        </div>
        </form>
    </body>
    </html>

  • 相关阅读:
    vue从入门到进阶:自定义指令directive,插件的封装以及混合mixins(七)
    js模板引擎mustache介绍及实例
    vue v-cloak 的作用和用法
    vue中$event理解和框架中在包含默认值外传参
    Node.js如何设置允许跨域
    前端常见跨域解决方案(全)
    http-server使用教程 hs -o
    JMeter性能测试,完整入门篇
    Java源码初学_LinkedHashMap
    Java源码初学_HashMap
  • 原文地址:https://www.cnblogs.com/skyshenwei/p/1660181.html
Copyright © 2011-2022 走看看