In my implementation, there are several forms on my page; If a post-back call was made by some control buttons, further operations are necessary.
The controls are of the following type, which does not populate Request["__EVENTTARGET"]
- Button (at the root of the form)
- Image Button (nested in Datagrid)
I determine if the following buttons initiated the post-back buttons by seeing that the UniqueID element of the control was passed to the form request in the Page_Load sub:
- ASP.NET: <asp:Button ID="Button1" runat="server" /> <asp:Button ID="Button2" runat="server" />
To simply handle whether the next button of the attached image has called post-back, I use the OnClientClick attribute, which calls the javascript function, which will populate the value of the additional hidden field with the UniqueID element and then look at the hidden control value in the same way in Page_Lode sub:
- ASP.NET: <script type="text/javascript"> function SetSource(SourceID) { var hiddenField = document.getElementById("<%=HiddenField1.ClientID%>"); hiddenField.value = SourceID; } </script> <asp:HiddenField ID="HiddenField1" runat="server" Value="" /> <asp:ImageButton ID="ImageButton1" runat="server" OnClientClick="SetSource(this.id)" />
Page_Load will then be implemented in some ways:
-VB.NET Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load ' ... If Not Page.IsPostBack Then If Not String.IsNullOrEmpty(Me.Page.Request.Form(Button1.UniqueID)) Then ' ... ElseIf Not String.IsNullOrEmpty(Me.Page.Request.Form(Button2.UniqueID)) Then ' ... ElseIf Not Me.Page.Request.Form(HiddenField1.UniqueID) Is Nothing _ And Not String.IsNullOrEmpty(Me.Page.Request.Form(HiddenField1.UniqueID)) Then ' ... HiddenField1.Value = String.Empty Else ' ... End If End If End Sub
samb0x
source share