Why would anyone use Button instead of LinkButton control in navigation
I am reworking some ui in an application written by freelance .Net developers from another country.
I won't go into how bad the code is and confusing the code with structure content and presentation ...
But one of the things I notice is that the menu to access parts of the application is done with Button controls that are sent to the server and return a different page. I would like to change the buttons to LinkControls, is there any reason people could do this?
I notice that when I go to LinkButtons, there is actually javascript that seems to trigger the post action. Any reasons or ways to avoid this?
source to share
You can repaint the buttons to look like links, then you can support any server-side code and not rely on javascript like LinkButton does.
.linkButton
{
background-color: transparent;
border-style: none;
color: /* Something nice */
cursor: pointer;
text-align: left;
text-decoration: underline;
display: table-cell;
}
Of course, if those buttons are just being used for navigation without any server side logic, then good old html links will only do fine ...
source to share
A LinkButton is a javascript anchor tag that submits a page form. If you don't want this behavior, then don't use the link button. Just use the standard anchor tag.
I've used LinkButtons in the past because it's a very simple way to combine button behavior with html regular link style. Noobs can also use them because they are an easy way to create a link and they don't know better yet.
source to share
One thing to consider when using LinkButton if you plan on using Ajax alot from Ajax solutions would be injecting javascript into LinkButton's OnClick event which is not a valid link event. Some browsers will process the code, like Internet Explorer, while others will ignore it, like Firefox.
source to share
You asked what is Link Control:
Simple and simple link management displays text that serves as a hyperlink that is used to process the form on the server side. A hyperlink can lead to a different form in the same ASP.NET web page or to any other URL.
The Link control must be placed in a form or panel control, or inside a control template. Enter the link text into the Text property. Use the NavigateUrl property to specify the target URL of the link.
With data binding, you can dynamically specify properties for the Link control. As such, it is fairly scalable for specific scenarios that cannot be determined until runtime.
source to share