我有一个与 ClientScript.RegisterOnSubmitStatement 绑定(bind)的函数,该函数在 UpdatePanel 更新时显示 JQuery UI 对话框(更新需要一段时间)。页面上有 2 个按钮,我想根据单击的按钮在对话框中显示不同的文本。有没有办法做这样的事情:
服务器端
ClientScript.RegisterOnSubmitStatement(this.GetType(), "ShowSplashScreen", "ShowSplashScreen(this)");
客户端
function ShowSplashScreen(source) {
// Do stuff depending on the button that was clicked
}
目前,“源”是 DOM 窗口,而不是按钮。
最佳答案
您可以使用__EVENTTARGET
来查找发起回发的控件:
/// <summary>
/// Retrieves the control that caused the postback.
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
private Control GetControlThatCausedPostBack()
{
Control ctrl = null;
//use the event target to get the control that initiated the postback
string ctrlName = Page.Request.Params.Get("__EVENTTARGET");
if (!String.IsNullOrEmpty(ctrlName))
ctrl = Page.FindControl(ctrlName);
//return the control to the calling method
return ctrl;
}
关于asp.net - 如何找出哪个按钮正在提交页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8247091/