I'm new to SO and fairly new to ASP.NET.
I have a LinkButton with an OnClientClick event, which I would like to execute some code before doing a crosspage postback.
This seems to work--I am able to retrieve the value from the next page--however, when I click "View" the HiddenField value is set to "Edit". I did some testing and it seems that all of the javascript functions are being called, regardless of which button is clicked. "Edit" is the last value set, so I am always retrieving the value "Edit" from my second page.
Javascript:
function viewfunc(control) {
<% hidden.Value = "View"; %>
<% hiddenpanel.Update(); %>
return true;
}
function editfunc(control) {
<% hidden.Value = "Edit"; %>
<% hiddenpanel.Update(); %>
return true;
}
Form:
<form id="form1" runat="server">
<asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server">
<asp:GridView Id="gridview1" runat="server" AllowPaging="True">
<Columns>
// Data fields here...
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="viewlabel" runat="server" Text="View" OnClientClick="if(!viewfunc(this)) return false;" PostBackURL="~/NextPage.aspx"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="editlabel" runat="server" Text="Edit" OnClientClick="if(!editfunc(this)) return false;" PostBackURL="~/NextPage.aspx"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" ID="hiddenpanel" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel runat="server">
<asp:HiddenField runat="server" Id='hidden' Value='Empty' />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
Note: I would have preferred to call these functions as codebehind functions, but I couldn't find a way to execute the codebehind after the click event but before the postback.
Thanks for any and all suggestions!