gpt4 book ai didi

asp.net - 哪个控件导致了回发?

转载 作者:行者123 更新时间:2023-12-02 06:38:14 26 4
gpt4 key购买 nike

我有两个按钮:

<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Button ID="Button2" runat="server" Text="Button" />

如何在 pageLoad 上确定这两者中哪一个导致了回发?据我所知,只有两个控件可以导致此回发,是否有一个简短的解决方案?

最佳答案

您可以使用此方法来获取导致回发的控件:

/// <summary>
/// Retrieves the control that caused the postback.
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
private Control GetControlThatCausedPostBack(Page page)
{
//initialize a control and set it to null
Control ctrl = null;

//get the event target name and find the control
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/7269271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com