Using an asp:hyperlink versus an asp:linkbutton

B

BobLaughland

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.
 
G

Guest

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
 
G

Guest

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top