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

  • Home
  • SEARCH
  • 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 158097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:37:17+00:00 2026-05-11T10:37:17+00:00

I have an aspx page defined as follows: <html xmlns=http://www.w3.org/1999/xhtml> <head runat=server> <title></title> <script

  • 0

I have an aspx page defined as follows:

<html xmlns='http://www.w3.org/1999/xhtml'> <head runat='server'> <title></title>     <script type='text/javascript' language='javascript'>        function changecolor() {            var lbl = document.getElementById('lblDisplayDate');            lbl.style.color = 'red';        };   </script>  </head> <body> <form id='form1' runat='server'> <div>     <asp:Label ID='lblDisplayDate' runat='server'                 Text='Label'></asp:Label><br />      <asp:Button ID='btnPostBack2' runat='server'                  Text='Register Client Block Script'                  onclick='btnPostBack2_Click' />  </div> </form> 

Here is the btnPostBack2 Click event:

protected void btnPostBack2_Click(object sender, EventArgs e) {     if (!ClientScript.IsClientScriptBlockRegistered('JSScriptBlock'))     {         ClientScript.RegisterClientScriptBlock(this.GetType(),          'JSScriptBlock',          'changecolor();',         true);     }  } 

Even though, I put the script in a function to change the color, it is still not doing it and why do I need to add the script tags to true if the function is already enclosed in script tags?

lblDisplayDate is in the Page Load where it is set to the current time on every page reload.

  • 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. 2026-05-11T10:37:17+00:00Added an answer on May 11, 2026 at 10:37 am

    Change this line:

    var lbl = document.getElementById('lblDisplayDate'); 

    to:

    var lbl = document.getElementById('<%= lblDisplayDate.ClientID %>'); 

    Also, this probably isn’t doing what you want it to do anyway. Try adding:

    OnClientClick='changecolor()' 

    to your <asp:Button /> tag.

    Edit At this point I am pretty confused as to what exactly you are trying to accomplish…

    If you just want to change the color of the label without posting back, change your <asp:Button /> to a normal <input type='button' /> with an onclick handler and call your script, like this:

    <input type='button' ... onclick='changeColor();' /> 

    If you want to change the color of the label while posting back, then just change the label’s background in the code-behind like this:

    protected void btnPostBack2_Click(object sender, EventArgs e) {     /* ... other stuff goes here ... */     lblDisplayDate.BackColor = Color.Red;     /* ... other stuff goes here ... */ } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Found - it is the Ant FixCRLF task. May 11, 2026 at 3:02 pm
  • added an answer It is good practice to minify your JS with a… May 11, 2026 at 3:02 pm
  • added an answer You can use the FileLocator class from org.eclipse.core.runtime to get… May 11, 2026 at 3:02 pm

Related Questions

i am using an asp:ImageButton server control; i set the CssClass attribute to my
I have a number of extension methods defined in my current project. It is
I have been working through Microsoft's ASP.NET MVC tutorials, ending up at this page
Whilst trying to get our app working in Firefox (I'm a big proponent of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.