The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Disable an asp.net LinkButton (or HyperLink) without graying it out

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Peter van Ooijen

Posts: 284
Nickname: petergekko
Registered: Sep, 2003

Peter van Ooijen is a .NET devloper/architect for Gekko Software
Disable an asp.net LinkButton (or HyperLink) without graying it out Posted: Sep 28, 2005 12:53 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Peter van Ooijen.
Original Post: Disable an asp.net LinkButton (or HyperLink) without graying it out
Feed Title: Peter's Gekko
Feed URL: /error.htm?aspxerrorpath=/blogs/peter.van.ooijen/rss.aspx
Feed Description: My weblog cotains tips tricks and opinions on ASP.NET, tablet PC's and tech in general.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Peter van Ooijen
Latest Posts From Peter's Gekko

Advertisement

I have a web form with a couple of linkbuttons. The linkbuttons serve as tab selectors, clicking one will activate an associated panel. When a panel is selected I don't want the user to select it again, clicking the linkbutton would be an unnecessary roundtrip. I can set the button's enabled property to false but the now the button will be grayed out. But this does not fit the user's impression of having precisely selected that tab.

Many asp.net controls have the AutoPostback property to disable an unintended postback. A linkbutton does not. But there is a very simple way to knock out postback with a snippet of script. This code does exactly what I want

LinkButton1.Attributes["OnClick"] = "return false;";
LinkButton1.CssClass = "HighlitedTab";
 

It sets the clientside click handler to the JavaScript statement return false; Which cancels postback. The appearance of the linkbutton is changed by setting its CSS class, so the user is informed about the status of the button. Both the attributes and the cssclass are included in the linkbutton's viewstate. To restore the control's original state on the next roundtrip you need to reset it from code or disable the control's viewstate.

This also works for a hyperlink. But I do not see a meaningful use for it there. Yet.

Read: Disable an asp.net LinkButton (or HyperLink) without graying it out

Topic: Team Foundation Server Beta 3 Great So Far and Dogfooding Previous Topic   Next Topic Topic: MVP Summit and Code Slam!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use