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 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

Related Questions

I have the following ASPX page: <html xmlns=http://www.w3.org/1999/xhtml > <head runat=server> <title></title> <script src=js/jquery-1.2.6.min.js
Currently I have a aspx page that is defined as: <%Using Html.BeginForm(SaveNotifications, Notifications, FormMethod.Post,
I have two nested repeaters in my *.aspx page. <asp:Repeater runat=server id=rptMain> <ItemTemplate> <h1><%#DataBinder.Eval(Container.DataItem,
I have an aspx page that includes a javascript file in the head tag.
In my asp.net 3.5 web site i have default.html page defined as first default
I have an aspx page with a simple form to send emails to pre-defined
I have a gridview defined in aspx page as defined below: have defined event
I have an aspx page that contains a dialog box defined with JQueryUI $('#dialog').dialog({
I have an aspx page with a few textboxes and a submit button. Once
I have an ASPX page .In the Top i am displaying 5 categories (Ex

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.