asp.net – 哪个控件导致回发?
发布时间:2020-07-03 09:05:05 所属栏目:asp.Net 来源:互联网
导读:我有两个按钮: asp:Button ID=Button1 runat=server Text=Button /asp:Button ID=Button2 runat=server Text=Button / 如何在pageLoad确定这两个哪一个导致回发? 有一个简短的解决方案,因为我知道只有两个控件,可以导致这种回发? 您可以使用此方法来获取
|
我有两个按钮: <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 – Html.Partial()跳过控制器动作
- asp.net-mvc – 使用Repository/Service Pattern和MVC时缓存
- asp.net-mvc – 在Azure Active Directory B2C中按组授权
- asp.net-mvc – 属性似乎根本不起作用
- asp.net-mvc – 如何在扩展方法中使用HTML帮助器方法?
- 服务器端ASP.Net Ajax异常处理
- asp.net-mvc – SSL握手问题? (当时:网页挂起,只清除浏览
- asp.net-mvc – 从Api控制器内生成绝对的url to action
- asp.net-mvc – MVC应用程序中的随机数生成
- asp.net – ASP MVC用户配置文件
