__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"];
    }
}

 

你可能感兴趣的:(post)