Wanna know the difference between the ASP.NET server controls HyperLink and LinkButton?
You're in the right place pal.
The major difference between the two - which will make you choose the one you need - is that The HyperLink will not PostBack your page to the server. It will post a simple request to the server for the URL you set as NavigateURL. The LinkButton works exactly as a normal Button but it looks like an HyperLink, so it will PostBack your page to the server allowing you to do your business (like setting variables at session level or doing some DB operation or whatever). Another (obvious) difference, which is more an imposed consequence of the above, is that the HyperLink doesn't have the OnClick event.
So, if you're asking yourself "which one should I use", here's the answer: if you need to do any operation with data that's on the page you will have to use a LinkButton (or a Button), but if you just need to redirect the user to somewhere else go for an HyperLink (You will avoid half roundtrip!).
E.g. you wanna avoid to have Button or LinkButton handlers with just this code:
which I do all the time, but - hey - I am a certified .NET butcher.
Cheers!
You're in the right place pal.
The major difference between the two - which will make you choose the one you need - is that The HyperLink will not PostBack your page to the server. It will post a simple request to the server for the URL you set as NavigateURL. The LinkButton works exactly as a normal Button but it looks like an HyperLink, so it will PostBack your page to the server allowing you to do your business (like setting variables at session level or doing some DB operation or whatever). Another (obvious) difference, which is more an imposed consequence of the above, is that the HyperLink doesn't have the OnClick event.
So, if you're asking yourself "which one should I use", here's the answer: if you need to do any operation with data that's on the page you will have to use a LinkButton (or a Button), but if you just need to redirect the user to somewhere else go for an HyperLink (You will avoid half roundtrip!).
E.g. you wanna avoid to have Button or LinkButton handlers with just this code:
Response.Redirect("Whatever.aspx");
which I do all the time, but - hey - I am a certified .NET butcher.
Cheers!
21 comments:
great and to the point answer.
very very nive blog to differentiate
thanx buther...brother
Great article !
My doubt is clear
Thankx dear.
Thanks! great article. Simple and clear!
nice one....keep it up...:-)
great answer..
exactly ur right.
thanq u.
great answer.
exactly you are right.
thank you.
Thnx 4 d answer
Very Well expalined
to the point answer
thank you :)
Thank U
Nice Answer really Thanks to you
very nice answer thanks.....frnds....
Great post.The answer was to the point.
Thanx pal.:)
Well almost...
The Hyperlink has one unique function that none of the ASP.Net buttons can do - to "target" (open) a second page/tab in the browser, which is very useful and needed in many cases.
gr8 ans
Thanks
Your knives are C sharp...
thank u well said :)
Thanks, explanation good
Post a Comment