I want to get a codebehind value in my javascript function. My scenario is, Lets say I have two Usercontrols A and B. I am setting a global value from UserControl A. When I come to UserControl B's page load, I am accessing that value and putting it into a hidden field. I have a button on UserControl B which calls a javascript function on client click. On that function I am trying to catch the hiddenfields current value. But I always get 0 from the hidden field value. What I am doing wrong? Can someone help me?
Below is the code:
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="DetailsForm.ascx.vb" Inherits="TD_Web_App.DetailsForm" %>
<script type="text/javascript">
function GetNextRecord() {
debugger;
var currentVal = $get("DetailsFormPanel_DetailsForm1_HFDetails").value;
//clientID of my hidden field
}
</script>
<asp:UpdatePanel ID="DetailInfoUpdatePanel" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<table id="TDPropsGrid" runat="server" width="250px" ></table>
<asp:Button ID="Cmd_Next" runat="server" Text="Next" Width="100px" SkinID="ButtonSkin" UseSubmitBehavior="false" OnClientClick="GetNextRecord()"/>
<asp:LinkButton ID="LinkButtonDetails" runat="server" style="display:none;">
LinkButton
</asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
<asp:HiddenField ID="HFDetails" runat="server" />
On code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
showData() 'some function
HFDetails.Value = CurrentRecordCounter ' global value coming from other usercontrol
End Sub
'Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
' HFDetails.Value = CurrentRecordCounter
'End Sub
I have tried putting
<asp:HiddenField ID="HFDetails" runat="server" />
inside the update panel, nothing changed.
But at GetNextRecord() the currentVal is always "0". why?