__doPostback在客户端控件中的作用

前台代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton ID="LinkButton1" runat="server"></asp:LinkButton>
<input type="button" id="thisTestBtn" value="客户端控件" onclick="javascript:__doPostBack('thisTestBtn','这就是按钮的内容!')" />
</div>
</form>
</body>
</html>

后台代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string targetID = Request.Params["__EVENTTARGET"];
string args = Request.Params["__EVENTARGUMENT"];
Response.Write(
"客户端按钮的ID为:"+targetID+"<br/>");
Response.Write(
"客户端按钮回传的值为:"+args);
}
}
}

得到的结果为:

客户端按钮的ID为:thisTestBtn
客户端按钮回传的值为:这就是按钮的内容!

原文地址:https://www.cnblogs.com/scy251147/p/1989754.html