Click here to Skip to main content
12,404,895 members (70,919 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB Javascript VB.NET
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;
alert(hdn)
}

<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
        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 8-Nov-12 17:34pm
Updated 8-Nov-12 17:47pm
v5

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Please try this..!

function show()
{
var hdn=document.getElementById('<%= hdnShow.ClientID %>').value;
alert(hdn)
}
  Permalink  
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


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100