Click here to Skip to main content
15,797,050 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:

function show()
var hdn=document.GetElementById('hdnShow').value;

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

VB.NET Code for Datagrid Event:

Protected Sub dgttumfileview_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgttumfileview.PageIndexChanged
            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 ??
Updated 8-Nov-12 18:47pm

1 solution

Please try this..!

function show()
var hdn=document.getElementById('<%= hdnShow.ClientID %>').value;
Share this answer
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)

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