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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:16:18+00:00 2026-05-16T03:16:18+00:00

i am using a series of linkbuttons A-z which are dynamically created what i

  • 0

i am using a series of linkbuttons A-z which are dynamically created what i want on the click of each its text color change to something else to make it different from others what i am doing

protected void Page_Init(object sender, EventArgs e)
    {
        // Adding Dynamically linkbuttons for all alphabets(i.e. A-Z)
        for (char asciiValue = 'A'; asciiValue <= 'Z'; asciiValue++)
        {
            LinkButton lbtnCharacter = new LinkButton();
            lbtnCharacter.ID = "lbtnCharacter" + asciiValue;
            divAlphabets.Controls.Add(lbtnCharacter);

            lbtnCharacter.Text = Convert.ToString(asciiValue);
            lbtnCharacter.CssClass = "firstCharacter";
            lbtnCharacter.ToolTip = "Show users whose name starts with '" + Convert.ToString(asciiValue) + "'";
            lbtnCharacter.CommandArgument = Convert.ToString(asciiValue);
            lbtnCharacter.Command += new CommandEventHandler(lbtnCharacter_Command);
        }
    }
void lbtnCharacter_Command(object sender, CommandEventArgs e)
    {
        ViewState["Selected_Character"] = e.CommandArgument;
        LinkButton lbtn = (LinkButton)divAlphabets.FindControl("lbtnCharacter" + e.CommandArgument);
        lbtn.ForeColor = System.Drawing.Color.Orange;
        txtNameFilter.Text = string.Empty;
        BindUserList();
    }

it is working fine but on clicking more then one buttons all the buttons which are clicked changes their color to orange but what i want is whichever button i click only that button color should change on click of next button previous button should go to default state is this approach right or tell me if it can be achieved by css

  • 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-16T03:16:19+00:00Added an answer on May 16, 2026 at 3:16 am

    Your problem is that the ViewState of the linkbuttons is being saved just before the controls are rendered, including the updated styling. Then, on your postback, after Page_Init, the ViewState is re-applied to each control, with the orange styling. This overrides the setting that you add in Page_Init. So in Page_Load, you need to reset the styling on each of the controls.

    Add another style to your stylesheet

    .highlighted { color:orange; }
    

    In lbtnCharacter_Command, replace

    lbtn.ForeColor = System.Drawing.Color.Orange;
    

    with

    lbtn.CssClass = "firstCharacter highlighted ";
    

    In Page_Load, add:

    foreach (var ctrl in divAlphabets.Controls)
    {
        if (ctrl is LinkButton)
            ((LinkButton)ctrl).CssClass = "firstCharacter";
    }
    

    On each Page_Load, all of the linkbuttons css class will be reset to the default. This is after the ViewState has been applied to them (between PageInit and PageLoad). Then on the Command event, the clicked button will have the new style appended. The color setting in this style will override whatever color setting is in the firstCharacter style.

    UPDATE

        protected void Page_Init(object sender, EventArgs e) {
            for (char asciiValue = 'A'; asciiValue <= 'Z'; asciiValue++) {
                var lbtnCharacter = new LinkButton {
                    ID = "lbtnCharacter" + asciiValue,
                    Text = Convert.ToString(asciiValue),
                    ToolTip = "Show users whose name starts with '" + Convert.ToString(asciiValue) + "'", 
                    CommandArgument = Convert.ToString(asciiValue)
                };
                lbtnCharacter.Command += lbtnCharacter_Command;
                divAlphabets.Controls.Add(lbtnCharacter);
            }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CurrentLetter"] != null) {
                foreach (var ctrl in divAlphabets.Controls) {
                    if (ctrl is LinkButton) {
                        if (((LinkButton) ctrl).Text == Session["CurrentLetter"].ToString()) {
                            ((LinkButton) ctrl).CssClass = "firstCharacter highlighted";
                        }
                    }
                }
            }
        }
    
        void lbtnCharacter_Command(object sender, CommandEventArgs e) {
            //Reset all of the other buttons only when clicking a new one
            foreach (var ctrl in divAlphabets.Controls) {
                if (ctrl is LinkButton) {
                    ((LinkButton) ctrl).CssClass = "firstCharacter";
                }
            }
            //Set the clicked button and save the Session state
            var lbtn = (LinkButton)divAlphabets.FindControl("lbtnCharacter" + e.CommandArgument);
            lbtn.CssClass = "firstCharacter highlighted";
            Session["CurrentLetter"] = lbtn.Text;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some logic which I am using to construct a series of clusters.
Hi i have a JavaFX LineChart and i want to redraw the series using
I want to use model-based clustering to classify 1,225 time series (24 periods each).
I'm using a series of commands called RelayCommand which have a function to execute
Using series.add(180, 1); produces a perfectly valid chart like this (little red dot at
I have been trying to approximate e using series representation to get as many
Ok I am trying to show a number using a series of Images. eg.
I've set up some charts using highcharts, populating it's series column using the brilliant
Using the following simulated time series: n=70 m1 = matrix(rnorm(n), ncol=7) m2 = matrix(rnorm(n,
We're using a DataView to display a series of buttons. The data comes from

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.