나는이 두 개의 버튼 :어떤 컨트롤에서 포스트 백이 발생 했습니까?
나는이 두 가지 중 하나가 포스트 백을 발생하는 pageLoad에 확인하는 방법을<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Button ID="Button2" runat="server" Text="Button" />
? 이 포스트 백이 발생할 수있는 컨트롤이 두 개 밖에 없다는 것을 알고있는 간단한 해결책이 있습니까?
/// <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;
}
http://aspnetnova.blogspot.com/2009/04/find-post-back-co ntrol-in-aspnet-page-c.html –