についてdoPostBack

2938 ワード

分からないところがあれば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";
        }