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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:45:26+00:00 2026-05-28T02:45:26+00:00

This is my code: <form id=form1 runat=server> <div> <asp:Label ID=Label1 runat=server Text=Label></asp:Label> <input type=button

  • 0

This is my code:

<form id="form1" runat="server">
<div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <input type="button" onclick="ontextchange();" />

    <asp:Button ID="Button1" runat="server"
        Text="Button" onclick="Button1_Click" />
</div>


function ontextchange() {

         document.getElementById("Label1").innerText="New";

    }

The problem is: I can change the lable value via javascript, but when I click the Button1, the lable value become the first one “Label”. How can I get the new value when I click the asp.net button?

  • 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-28T02:45:26+00:00Added an answer on May 28, 2026 at 2:45 am

    You may try to use a hidden field instead, but you need to keep them synchronized in your client-side script and your server-side event handler.

    <asp:Hidden ID="Hidden1" runat="server" />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    

    In JavaScript:

    function ontextchange() {
      // Set the label for the visual result
      document.getElementById("Label1").innerText="New";
      // Set the hidden input for the server
      document.getElementById("Hidden1").value="New";
    }
    

    Server-side you can read the hidden input and update the label (again, keeping them synchronized):

    protected void Button1_Click(object sender, EventArgs e)
    {
      // Set the label text to the value from the hidden input
      string value = Hidden1.Value;
      Label1.Text = value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used this code to print the current page: <form> <input type=button value=Print onClick=window.print();
I have this code: <div class=LoginBox> <form id=form2 runat=server> <asp:ContentPlaceHolder ID=ContentPlaceHolder2 runat=server> lolbags </asp:ContentPlaceHolder>
Page: <body> <form id=frmLogin runat=server> <asp:Button ID=btnClick OnClientClick=openConfirmDialog(); OnClick=PopulateLabel runat=server/> <div id=divDialog></div> <asp:Label ID=lblText
I got this code in my submit form <form id=myform action='hello.php' method='GET'> <input type=button
This is my code in aspx page <head runat=server> <title></title> <script src=//Scripts/jquery-1.4.1.js type=text/javascript> </script>
master1.master Html <div id=message style=direction: rtl; display: none> </div> <form id=form1 runat=server style=padding: 0px;>
I found this code from here: http://www.cssportal.com/form-elements/text-box.htm But the problem is you can still
This code is executed by many way. When it's executed by the form button
I have small page which has label, DropDownList and a submit button. <div> <asp:label
Below is the code of my Web Content Form. The DIV inside ASP tag

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.