Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have function in javascript and a hiddenfield. I'm initializing hiddenfiled with value="False" and I set the value for hiddenfiled in Page event for Datagrid as "True". Now I'm calling my javascript function from Page event form codebehind where I need to check the value of hiddenfield but the value which is set as "True" is not displayed in alert box for the first time i.e. for the first time it shows value as "False" and from second time it shows correct value as "True".

Javascript code is:

JavaScript
function show()
{
var hdn=document.GetElementById('hdnShow').value;
alert(hdn)
}


ASP.NET
<asp:HiddenField Id="hdnShow" Value="False" runat="Server" />


VB.NET Code for Datagrid Event:

VB
Protected Sub dgttumfileview_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgttumfileview.PageIndexChanged
        Try
            hdnShow.Value="True"
            If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "show();", True)
            End If
                    Catch ex As Exception
            Trace.Warn("dgUnPaidScroll_PageIndexChanged", ex.Message)
        End Try
    End Sub



How can I get the correct set value for hiddenfield from first time when I call javascript function ??
Posted
Updated 8-Nov-12 17:47pm
v5

1 solution

Please try this..!

JavaScript
function show()
{
var hdn=document.getElementById('<%= hdnShow.ClientID %>').value;
alert(hdn)
}
 
Share this answer
 
v2
Comments
swatiiiiiiiiii 9-Nov-12 4:17am    
It gives error 'Object doen't support this property'
Ravi Tuvar 9-Nov-12 6:38am    
May you try and see the updated solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900