Solved

How to remove underline and disable a Linkbutton in ASP.Net after clicking and maintain this status across postbacks?

Posted on 2009-05-06
9
2,810 Views
Last Modified: 2013-11-07
I'm using a Multiview control having 6 views. I'm also using 6 LinkButtons named as  1 2 3 4 5 6. Each of the LinkButton when clicked causes a postback and sets the corresponding ActiveIndexView property of the Multiview control.

I would like to remove the underline and disable the Linkbutton which is clicked at any point and keep the remaining five active. Also, each of the views have controls like dropdown which also cause postback. So, its important for me to persist the disabled state of the most recent clicked Linkbutton and keep the remaining five active. I'm using ASP.Net 2.0 with C# as the code-behind.

Thanks
0
Comment
Question by:pb102674
  • 5
  • 4
9 Comments
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 24314777
on the event handler of all the link buttons you will need to update a field. then run a method.

you will need to add this to the top of your page. under the <title>

<style type="text/css" media="screen">
      .LinkNoUnderline
      {
         text-decoration:none;
      }
    </style>

maybe viewstate :
example I click on Link1:

ViewState["LastClickedID"] = "Link1"; //Store the ID in the viewstate.
RefreshLinks(); //Update the links

then you would need to add the method:

void RefreshLinks() {
      switch (ViewState["LastClickedID"].ToString()) {
         case "Link1":
            Link1.Attributes.Add("class", "LinkNoUnderline");
            Link1.Enabled = false;
            break;
         case "Link2":
            Link2.Attributes.Add("class", "LinkNoUnderline");
            Link2.Enabled = false;
            break;
         case "Link3":
            Link3.Attributes.Add("class", "LinkNoUnderline");
            Link3.Enabled = false;
            break;
         case "Link4":
            Link4.Attributes.Add("class", "LinkNoUnderline");
            Link4.Enabled = false;
            break;
         case "Link5":
            Link5.Attributes.Add("class", "LinkNoUnderline");
            Link5.Enabled = false;
            break;
         case "Link6":
            Link6.Attributes.Add("class", "LinkNoUnderline");
            Link6.Enabled = false;
            break;
      }
   }

That should do what you need.

Ghost
0
 

Author Comment

by:pb102674
ID: 24315737
Thanks for the response.

As I had mentioned in my question, each of the views have controls like dropdown which also cause postback. So, its important for me to persist the disabled state of the most recent clicked Linkbutton and keep the remaining five active.

I used the code above. What happens is when a dropdown in a view causes a postback, the clicked LinkButton again shows up as active.

As an example, View3 has a dropdown. When I click Linkbutton 3, it initially shows with no underline and disabled. But when an item in the dropdown in View3 is selected, it causes a postback and  Linkbutton 3 shows up as active and clickable. In reality, Linkbutton should show with no underline and disabled.

I have EnableViewState property of all LinkButtons set to false. Do I have to do something in Page_OnLoad event?

Thanks

0
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 24315780
yes sorry I forget to include that part
in your page load you must call:
RefreshLinks();

That will ensure you are keeping the data. Also don't disable the viewstate. that's important so asp.net can track your link button's state (enabled, disabled)
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:pb102674
ID: 24316048
Doesn't work. Let's say if I click on LinkButton 2 and then click on LinkButton 3, both 2 and 3 show up as Disabled. If I click on Linkbutton 4, Linkbuttons 2, 3, and 4 show up as disabled.

However, the postback issue of dropdown I mentioned in my previous comment is now taken care of. I have the EnableViewState set to true for all LinkButtons.

Here's my code:

protected void Page_Load(object sender, System.EventArgs e)
{
      //This is because for the first time, View 1 is shown by default
      if (!IsPostBack)
        {
              ViewState["LastClickedID"] = lbGoToPage1.ID;
        }
      
      RefreshLinks();

}

//LinkButton code, likewise I have the same code for the remaining five buttons.
protected void lbGoToPage1_Click(object sender, System.EventArgs e)
{
            //Store the ID in the viewstate.
            ViewState["LastClickedID"] = lbGoToPage1.ID;

           
            //Update the links
            RefreshLinks();

            MultiView1.ActiveViewIndex = 0;
}



private void RefreshLinks()
        {
            switch (ViewState["LastClickedID"].ToString())
            {
                case "lbGoToPage1":
                    lbGoToPage1.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage1.Enabled = false;
                    break;
                case "lbGoToPage2":
                    lbGoToPage2.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage2.Enabled = false;
                    break;
                case "lbGoToPage3":
                    lbGoToPage3.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage3.Enabled = false;
                    break;
                case "lbGoToPage4":
                    lbGoToPage4.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage4.Enabled = false;
                    break;
                case "lbGoToPage5":
                    lbGoToPage5.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage5.Enabled = false;
                    break;
                case "lbGoToPage6":
                    lbGoToPage6.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage6.Enabled = false;
                    break;
            }
        }
0
 
LVL 13

Accepted Solution

by:
copyPasteGhost earned 300 total points
ID: 24316111
:) of course...

Here...

void EnableAll(){
      lbGoToPage1.Enabled = true;
      lbGoToPage2.Enabled = true;
      lbGoToPage3.Enabled = true;
      lbGoToPage4.Enabled = true;
      lbGoToPage5.Enabled = true;
      lbGoToPage6.Enabled = true;
   }

private void RefreshLinks()
        {
EnableAll();
            switch (ViewState["LastClickedID"].ToString())
            {
                case "lbGoToPage1":
                    lbGoToPage1.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage1.Enabled = false;
                    break;
                case "lbGoToPage2":
                    lbGoToPage2.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage2.Enabled = false;
                    break;
                case "lbGoToPage3":
                    lbGoToPage3.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage3.Enabled = false;
                    break;
                case "lbGoToPage4":
                    lbGoToPage4.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage4.Enabled = false;
                    break;
                case "lbGoToPage5":
                    lbGoToPage5.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage5.Enabled = false;
                    break;
                case "lbGoToPage6":
                    lbGoToPage6.Attributes.Add("class", "LinkNoUnderline");
                    lbGoToPage6.Enabled = false;
                    break;
            }
        }


Try that now.
0
 

Author Closing Comment

by:pb102674
ID: 31578391
Thank you. I appreciate your time and efforts. I will be posting a few more questions specific to other scenarios in my application. So, I would really appreciate if you could respond to those questions.

Thanks again.
0
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 24316389
sure just post the links to the questions here so I'll get them.
0
 

Author Comment

by:pb102674
ID: 24316478
I sure will. Thanks.
0
 

Author Comment

by:pb102674
ID: 24316711
Hi - Here's the link to the latest question I entered. Please help me out.

http://www.experts-exchange.com/index.jsp?qid=24385624
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question