views:

375

answers:

5

I am reworking some ui in an application written by freelance .Net developers from another country.

I am not going to go into how bad the code is and entangled the code with structure content and presentation are...

But one of the things I notice is that menu for accessing the parts of the app is made with Button controls that post to the server and return a different page. I would like to change the buttons to LinkControls are there any reasons that people might have done this ?

I notice that when I do change to to LinkButtons there is actually javascript that seems to trigger the post action. Any reasons or ways to avoid this ?

A: 

A LinkButton is just that--an anchor tag with javascript that submits the page's form. If you don't want that behavior, don't use a link button. Just use a standard anchor tag.

I've used LinkButtons in the past because its a very easy way to merge the behavior of a button with the style of a regular html link. Noobs might also use them because its a simple way to create a link and they don't know better yet.

Will
A: 

If all you want are anchors whose properties can be manipulated on the server-side and which don't post back to the server, then use HyperLink control. If you want to post the clicks back to server, then use LinkButton control.

Kon
+2  A: 

You could re-style the buttons to look like links, then you can maintain any server-side code, and not have to rely on javascript like the 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 these buttons are simply used for navigation without any server side logic, then good old html links would do just fine...

Phil Jenkins
I might actually revisit this
Salt Packets
This is really useful Phil. I've been looking for this..
Lee Englestone
A: 

One thing to keep in mind with LinkButton's if you're planning to use Ajax alot of Ajax solutions will insert javascript on the LinkButton's OnClick event which is not a valid event for a link. Some browsers will handle the code such as internet explorer while others will ignore it such as Firefox.

Chris Marisic
A: 

You asked what is a Link Control:

Plain and simple the Link control displays text that serves as a hyperlink that is used for server-side form processing. The hyperlink can lead to another form on the same ASP.NET Web page or to any other URL.

A Link control must be placed within a Form or Panel control, or within a control's template. Enter the link's text into the Text property. Use the NavigateUrl property to specify the link's destination URL.

With data binding, you can supply the properties for the the Link control dynamically. So its quite extensible under specific scenarios that can't be determined till run-time.

JohnL