zoukankan      html  css  js  c++  java
  • __doPostBack的使用

    <script type="text/javascript">...
    <!--
    var theForm = document.forms['form1'];
    if (!theForm) ...{
        theForm = document.form1;
    }
    function __doPostBack(eventTarget, eventArgument) ...{
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) ...{
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }

    //前台html
    <form id="form1" runat="server">
        <div>
        <asp:linkbutton runat="server" ID="linkbutton" OnClick="linkbutton_Click">LinkButton</asp:linkbutton>
        <input type="button" value="dianji" onclick="__doPostBack('CE_','1234')" />
        <input type="button" value="changshi" onclick="__doPostBack('CE_doClinetEvent','1234')" />
            <asp:LinkButton ID="CE_" runat="server">LinkButton</asp:LinkButton>
           
            </div>
        </form>
    //============================
    //后台代码

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    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;
    using System.Reflection;

    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (this.IsPostBack)
            {
                if ((Request.Form["__EVENTTARGET"] != null) && (Request.Form["__EVENTTARGET"] != ""))
                    if (Request.Form["__EVENTTARGET"].Substring(0, 3) == "CE_")//Request.Form = {__EVENTTARGET=CE_&__EVENTARGUMENT=1234&__VIEWSTATE=%2fwEPDwUKLTY1ODg1NjQ0NGRkbhoXkuSAXe5LLYKYUC5wjRrOSXo%3d}
                    {
                        Control c = Page.FindControl(Request.Form["__EVENTTARGET"]);
                       
                        LinkButton lb= c as LinkButton;
                       
                        String strEventArgument = Request.Form["__EVENTARGUMENT"];
                        Type type = this.GetType();
                        MethodInfo mi = type.GetMethod(Request.Form["__EVENTTARGET"], BindingFlags.Instance | BindingFlags.NonPublic);
                        if (mi != null) mi.Invoke(this, new object[] { strEventArgument });
                    }
            }
        }
        protected void CE_doClinetEvent(string AArgument)
        {
            Response.Write("這是一個測試");
         
        }
        protected void linkbutton_Click(object sender, EventArgs e)
        {
            Response.Write("123");
            string tarargument = Request.Form["__EVENTARGUMENT"];
        }
    }

  • 相关阅读:
    第 14 章 结构和其他数据形式(names3)
    第 14 章 结构和其他数据形式(names)
    第 13 章 文件输入/输出 (把文件附加到另一个文件末尾)
    第 13 章 文件输入/输出 (标准I/O)
    第 12 章 存储类别、链接和内存管理(存储类别)
    JS鼠标滚轮判断向上还是向下滚动
    js中一些自带方法和属性
    函数的传入的参数(实参和形参)
    css3实现翻书效果
    redis集群安装
  • 原文地址:https://www.cnblogs.com/jazzka702/p/1566209.html
Copyright © 2011-2022 走看看