关于__doPostBack

如有不明白的地方欢迎加QQ群 14670545 探讨
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="MyWebSiteTest.Reflection.WebForm1" %>

<!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>
    <style type="text/css">
        *{ font-family:Arial; font-size:14px; line-height:23px;}
        body{ background-color:#FAF9DE; }
    </style>
</head>
<body>
     <%--银河白 #FFFFFF rgb(255, 255, 255)   
        杏仁黄 #FAF9DE rgb(250, 249, 222)    
        秋叶褐 #FFF2E2 rgb(255, 242, 226)    
        胭脂红 #FDE6E0 rgb(253, 230, 224)    
        青草绿 #E3EDCD rgb(227, 237, 205)    
        海天蓝 #DCE2F1 rgb(220, 226, 241)    
        葛巾紫 #E9EBFE rgb(233, 235, 254)    
        极光灰 #EAEAEF rgb(234, 234, 239)--%>
    <form id="form1" runat="server">    
    <div style=" width:960px; margin:0 auto;">
        <div style=" height:100px;"></div>
        <asp:LinkButton runat="server" ID="likbtn" />
        <%--第一个参数表示按钮ID,第二参数随便写的,为的就是在后台确定按钮是否被点击了。 --%>
        <div style=" border:2px solid #C60A00; padding:10px; width:80px;"><%=outHTML %></div><br />
        <button type="button" id="btnConfirm" onclick="__doPostBack('btnConfirm','1')">查询</button>
        <button type="button" id="btnPostBack" onclick="__doPostBack('FF',1)">测试</button>

        <%--<a id="A1" href="javascript:__doPostBack('likbtn','')"></a>--%>


    </div>
    </form>
</body>
</html>
public partial class WebForm1 : System.Web.UI.Page
    {
        public string outHTML = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            string controlName = Request.Params.Get("__EVENTTARGET");
            string eventArgument = Request.Params.Get("__EVENTARGUMENT");


            // 确定按钮事件
            if (controlName == "btnConfirm" && eventArgument == "2")
            {
                btnConfirm_Click(sender, e);
            }

            // 查询按钮事件
            if (controlName == "FF" && eventArgument == "1")
            {
                btnReturn_Click(sender, e);
            }
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            outHTML = "btnConfirm";
        }
        private void btnReturn_Click(object sender, EventArgs e)
        {
            outHTML = "FF";
        }


你可能感兴趣的:(关于__doPostBack)