Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Using an asp:hyperlink versus an asp:linkbutton

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BobLaughland - 15 Aug 2007 00:05 GMT
Hi There,

I need a control on my site that is a hyperlink style control, but it
must,

1) Have a property that can hold where the hyperlink is pointing to.
(e.g. like the NavigateUrl property in the asp:hyperlink control).
2) Also can call my own method when the user clicks on the link (e.g.
like the Click event in the asp:linkbutton control).

Anyway it seems that the 2 controls separately do what I want, but
don't both do everything I want.

I will explain why. Basically what I have is a page which shows the
results from the user doing a search. It lists the results from the
search as hyperlinks (kind of like doing a search in google but local
to our site). When the user clicks on one of the links I would like it
to call a piece of my code to log which link they clicked for
statistical purposes. Also note that it has to know the page that it
is linking to (the asp:linkbutton does not have a NavigateUrl property
so this does not work).

Failing that the only other way I can think of doing it would be to
subclass one of the above controls and add the functionality, but that
sounds messy to me.
Ladislav Mrnka - 15 Aug 2007 08:04 GMT
Hi,
you are trying to combine two absolutly different functionality. NavigateUrl
is used in browser to construct new GET HTTP request and point it to
described resource on web server - this means you actual page cannot response
to this request because it will not be posted back. On the other hand link
button uses post back mechanism = user usually constructs POST HTTP (type of
request can be changed) request and sends it to you current page for
processing.

You have to choose another approach to solve your requirements. You can use
link button and post back you url or any other identifier as command
argument. Then you can handle logging in on command event and transfer
(server side - url will be same as search page) or redirect (client side - if
you want url to reflect actual user choice but it means one more round trip)
to page you want to display as response to user click. Another approach you
can choose is to use hyperlink and add some query string to NavigateUrl to
inform your application to log user request. You can handle logging in each
page or for example in custom http module.

Regards,
Ladislav

> Hi There,
>
[quoted text clipped - 21 lines]
> subclass one of the above controls and add the functionality, but that
> sounds messy to me.
Alexey Smirnov - 15 Aug 2007 08:20 GMT
On Aug 15, 9:04 am, Ladislav Mrnka
<LadislavMr...@discussions.microsoft.com> wrote:
> Hi,
> you are trying to combine two absolutly different functionality. NavigateUrl
[quoted text clipped - 17 lines]
> Regards,
> Ladislav

I fully agree. In addition to Ladislav's proposals you can try
following:

- use Hyperlink Control with onclientclick property where you can call
an Ajax function before client will be redirected to the NavigateUrl.
- use Hyperlink Control pointed to another webform, e.g. redirect.aspx?
url=http://mysite/mypage where url will be your target url and write
your statistics from the redirect.aspx
- use HttpHandler and check HTTP_REFERER. if the referrer is the
address of your search page then you can log that request.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.