473,766 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using an asp:hyperlink versus an asp:linkbutton

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.

Aug 14 '07 #1
2 2813
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

"BobLaughla nd" wrote:
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.

Aug 15 '07 #2
On Aug 15, 9:04 am, Ladislav Mrnka
<LadislavMr...@ discussions.mic rosoft.comwrote :
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.

Aug 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
7385
by: Fresh Air Rider | last post by:
Hello Could anyone please explain how I can pass more than one arguement/parameter value to a function using <asp:linkbutton> or is this a major shortfall of the language ? Consider the following code fragments in which I want to list through all files on a directory with a link to download each file by passing a filename and whether or not to force the download dialog box to appear.
5
3749
by: Fresh Air Rider | last post by:
Hello Could anyone please explain how I can pass more than one arguement/parameter value to a function using <asp:linkbutton> or is this a major shortfall of the language ? Consider the following code fragments in which I want to list through all files on a directory with a link to download each file by passing a filename and whether or not to force the download dialog box to appear.
2
2471
by: Manish Naik | last post by:
Hi, Using ASP.Net, I want to store and retrive documents (Word, excel, etc) from SQL Server 2000 database. I have tried image type data field, but could not succed. Can any one help me please. Regards, Manish Naik
5
3298
by: George Durzi | last post by:
I currently have an href inside of an asp:repeater <a href='<%# String.Concat("PDFReader.aspx?id=", DataBinder.Eval(Container.DataItem, "ProductUniqueId")) %>' target="_blank">View</a> Clicking View will open a new browser and load PDFReader.aspx My client would like me to hide the address bar and toolbar on this new
5
1979
by: Davíð Þórisson | last post by:
sorry my lazyiness (for not Googling!), I'm looking for the .Net way to do this classical asp setup (Jscript)... <a href="page.asp?action=do1">bla bla1</a> <a href="page.asp?action=do2">bla bla2</a> ... -------- and correspondingly:
2
1250
by: nicknack | last post by:
Hello. I have an asp:hyperling in my page and I'm trying to make it "clicked" from my code behind. Is this possible? I also tried it with JS but its look like the hyperlink doesn't have a "click()" method :( Any body have an idea?
3
2898
by: Ganesh | last post by:
Hi There, It should be easy question, but i don't know how to do. How to transfer to another website from my page. I tried with linkbutton and Hyperlink but i cannot figure out always it transfer to http://localhost:4111/www.yahoo.com
2
19147
by: dddan | last post by:
Here's my code: <asp:LinkButton OnClick="DeleteFile" OnClientClick="if (!confirm ('Are you certain you want to delete this file?') ) return false;" runat="server" ID="DeleteButton">DELETE </asp:LinkButton>
2
4452
by: =?Utf-8?B?QWxleA==?= | last post by:
I have an asp linkbutton declared as follows: <asp:LinkButton ID="LinkButton1" runat="server" CssClass="tt">ASP Link Button</asp:LinkButton> My CSS classes are declared as follows: a.tt { color:Black; text-decoration: none; border-bottom: 1px dashed Blue;
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.