Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7007471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:36:41+00:00 2026-05-27T21:36:41+00:00

I have been searching through here and google for a few days now, trying

  • 0

I have been searching through here and google for a few days now, trying to figure out why I cannot get the value of a hiddenfield variable in javascript. When accessed, the value is returned as undefined.
I have an ASP HiddenField inside an UpdatePanel which is part of a custom user control in a .aspx web page (standard issue).

In my user control, I need to get the .Value of the HiddenField (hdnServer) in javascript after setting it in C#. But for some reason the following is not getting the correct value.

The MessageBox in the C# code returns the correct value (the code here has test values), but when accessed in javascript is undefined.

userControl.ascx:

//this function is called when the timer created in document.ready() elapses
//returns the correct hdnServer value in the check. 
    var checkHdn = function () {
        var temp = document.getElementById("<%=hdnServer.ClientID%>").value;
        temp = temp.toString();
        if (temp != "") {
            $('#LoadingViewer').hide();
            clearInterval(checkSrv);

            //enable start button
            $('#startBtn').attr("Enabled", "true");
        }
    };

  function RdpConnect() {

                //serverName = undefined here.  should be ip address when set in c# 
                var serverName = document.getElementById("<%= hdnServer.ClientID %>").value;
                alert(serverName);
                if (serverName != "") {
                    MsRdpClient.Server = serverName;
                }
            };

userControl.ascx.cs code-behind:

public partial class userControl : System.Web.UI.UserControl
    {
        System.Timers.Timer timer; 

        protected void Page_Load(object sender, EventArgs e)
        {
            timer = new System.Timers.Timer(5000);
            timer.Start();
        }

        protected void testOnTick(object sender, System.Timers.ElapsedEventArgs e)
        {
                hdnServer.Value = "test value";
                startBtn.Enabled = true;
                timer.Enabled = false;
        }
    }

Here is the asp for HiddenField just in case: userControl.ascx:

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
    <Triggers>
         <!--trigger not used  -->
       <!-- <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />-->
    </Triggers>
    <ContentTemplate>
        <asp:HiddenField ID="hdnServer" runat="server" />
        <asp:Label ID="Label1" Text="Loading, please wait." CssClass="loading" runat="server"
            Font-Size="XX-Large" />
    </ContentTemplate>
</asp:UpdatePanel>

Thank you for any advice in advance!

EDIT: messagebox removed..
Here is rendered html: http://pastie.org/3122247

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:36:42+00:00Added an answer on May 27, 2026 at 9:36 pm

    You need to set ClientIDMode if you want to make it simple:

    <asp:HiddenField runat="server" ClientIDMode="Static" Id="hidServer"/>
    
    <script type="text/javascript">
      alert($("#hidServer").val());
    </script>
    

    Or, use the ClientID property if you don’t set ClientIDMode:

    <asp:HiddenField runat="server" Id="hidServer"/>
    
    <script type="text/javascript">
      alert($("<%= hidServer.ClientID %>").val());
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been searching for a solution for a few days now, I've looked through
For a long time now I have been searching through the forum whilst teaching
I have been searching to figure out how exactly to use the oauthable module
I have been searching high and low for a way to get my silverlight
I have been searching around using Google but I can't find an answer to
I'm new here and somewhat inexperienced with C#. I've been searching through the MSDN
I have been searching for several hours now and have so far had no
I've searching forever trying to figure out why IE will not save the current
I'm sure this question HAS to have been asked, but after searching through the
I have been searching for about 2 hours now without any luck, maybe I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.