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 6469447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:59:30+00:00 2026-05-25T05:59:30+00:00

I set the value of the controls when the DOM loads. I have this

  • 0

I set the value of the controls when the DOM loads. I have this super simple code on aspx page:

 <script type="text/javascript">
        $(document).ready(function () {
            $('#<%=textBox2.ClientID %>').val($('#<%=textBox1.ClientID %>').val());
            $('#<%=lblVal.ClientID %>').html($('#<%=textBox1.ClientID %>').val());

        });
    </script>

        <asp:TextBox runat="server" ID="textBox1" Text="Test data" />
        <asp:TextBox runat="server" ID="textBox2" />
        <asp:Label runat="server" ID="lblVal" Text="Old Data" />
        <asp:Button runat="server" Text="Click Me" onclick="Unnamed1_Click" />

In my button click event handler I have this code:

protected void Unnamed1_Click(object sender, EventArgs e)
    {
        Debug.Write(textBox2.Text);
        Debug.Write(lblVal.Text);
    }

The thing that came shocking to me lblVal has it’s old value. Setting value in javascript doesn’t really have any effect on label whereas the textbox2’s data is reflected on the server. Is the intended behavior of textbox and label? This came as a bit of surprise to me because I never came across this thing previously.

  • 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-25T05:59:31+00:00Added an answer on May 25, 2026 at 5:59 am

    The label will get rendered to an HTML label tag, not a form field. Therefore it does not have a value that is posted when the form is submitted, and the value you get restored in the postback is from ViewState. Form fields (e.g. a ASP TextBox which becomes an input) will post their value and this will override the value in viewstate.

    You could get around this by instead having a hidden input which you update with javascript, and then in your postback update the label with the contents of that instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I put a form control on the page with a value already set,
Running the following code: dojo.toJson(formSearch.attr(value)); Appears to not serialize the value of dijit.form.DateTextBox controls.
I have inherited an application that uses telerik controls. This is my first time
I have a few Devexpress aspx controls on a website that look fine on
I have an application with two Canvas controls. When the application starts, it loads
Here is my situation. I have multiple user controls in a canvas. This canvas
i have JS which return the value function sendDisplay() { var dis = alert(reader.dom.find('controls_contents_container').style.display);
i want to get and set the value of controls define in XML Layout
How could I set the value of the Height property of a WPF control
I need to write a generic procedure that set value for one column or

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.