
__doPostback在客户端控件中的作用
发布日期:2021-05-14 04:36:51
浏览次数:17
分类:精选文章
本文共 1546 字,大约阅读时间需要 5 分钟。
前台代码如下:
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " Default.aspx.cs " Inherits = " _Default " %> < html xmlns = " http://www.w3.org/1999/xhtml " > < head runat = " server " > < title > < body > < form id = " form1 " runat = " server " > < div > < asp:LinkButton ID = " LinkButton1 " runat = " server " > < input type = " button " id = " thisTestBtn " value = " 客户端控件 " onclick = " javascript:__doPostBack('thisTestBtn','这就是按钮的内容!') " />
后台代码如下:
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 + " " ); Response.Write( " 客户端按钮回传的值为: " + args); } } }
得到的结果为:
客户端按钮的ID为:thisTestBtn
客户端按钮回传的值为:这就是按钮的内容!