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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:34:18+00:00 2026-06-01T11:34:18+00:00

I need to know how to change the css class on a tag on

  • 0

I need to know how to change the css class on a tag on page load.. in PHP this was much easier all i had to do is to write <tagNAme class="<?php echo "className"; ?>"> …

I was able to write php code blockes with in tags.. but in ASP .NET this doesn’t seem to work

I tried <% tagElementId.attribute.add("class","cssName"); %> after the tag i wanted to change the css in ASPX file….but didn’t work..

My scanario is i need to check password textbox and on login button click..if the password is wrong password textbox should have a class called “error” otherwise a css class named “userinput”

How do I do it?

EDIT

<form id="loginPanel" runat="server">
        <ul>
            <li>
                <h3>
                    Log on</h3>
            </li>
            <li>
                <label for="userId">
                    User ID :</label>

                <asp:TextBox ID="userId" name="userId" class="loginTextInput" runat="server"></asp:TextBox>

            </li>
            <li>
                <label for="password">
                    Password :</label>

                <asp:TextBox ID="password" name="password" class="loginTextInput" 
                    runat="server" ontextchanged="password_TextChanged"></asp:TextBox>

            </li>
            <li>
                <asp:Button ID="logInButton" runat="server" Text="Log on" OnClick="logInButton_Click" />
                <li class="forgotUserText">Forgot <a href="#" class="forgotUser">User ID </a>or <a
                    href="#" class="forgotUser">Password?</a> </li>

        </ul>
        </form>

`

  • 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-06-01T11:34:19+00:00Added an answer on June 1, 2026 at 11:34 am

    MyPage.aspx

    <asp:Label ID="myLabel" Text="Some text in span" runat="server" />
    

    MyPage.aspx.cs

    protected void Page_Load(object sender, EventArgs e)
    {
        myLabel.CssClass = "someNewClass";
    }
    

    I want to point out one more thing – try not to mix aspx (html) pages with the logic like in your example. It’s a bad habit. In php you don’t really have any alternatives, but you try to work in asp.net now, so you need to get rid of your old habits and think completely different.

    EDIT based on your comment about Curt’s answer:

    If you want to ADD some class to the existing one, you can do it something like that:

    myLabel.CssClass += " someNewClass";
    

    EDIT based on the last comment (and the last one, because this begins to be a completely different question! Create new question and I suggest to do some research first, so we don’t have to explain all the basics)

    You just need to set attribute runat=”server” for the element you want to modify by your code-behind and be sure you set its ID as well. Then, you can do something like this:

    Label myDynamicNewLabel = new Label();
    myDynamicNewLabel.Text = "Let's say this is an error message";
    
    myParentElement.Controls.Add(myDynamicNewLabel);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to know how much space occupies all the databases inside an SQL
I need to change all the CSS into SASS... and find that margin:10px working
This is probably really simple, I know you can change css properties with javascript
I need to know when a sharer has been authorized (to change some UI)
Need to know this so that i could send DTMF and that is going
I am using this picker for my projects and I need to change the
My web application target to major Smartphones and I need to change the CSS
I have this a and I don't know that I need to insert into
Need to know which event triggered after text selection done in Apple iPad. It
I need to know about Epoll On linux System. Could you recommend manual 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.