473,511 Members | 14,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I call a function from a hyperlink in C# ?

Could anyone please tell me how I can call a function from a hyperlink
in C# ?

Examples of scenarios where this would be useful include :-

Loop through a set of records in a repeater and have a hyperlink to
edit each record by passing it's record id to another page.

Loop through a set of files on a server and have a hyperlink to
download a file via a stream on another page by passing its filename
(this is so that the full path of the file is not revealed to the
user).

ie

I have a function within "Codebehind" (which works fine).

public void DownloadFile( string fname,bool forceDownload)
{
.......
.......
.......
}

I have tried calling the function from the ASP page in various ways
such as :-

<asp:HyperLink NavigateUrl="<%#DownloadFile("test.doc",true)%>">D ownload
file</asp:HyperLink>

This method results in the error "The best overloaded method match for
'System.Convert.ToString(object)' has some invalid arguments"

I have tried various permutations of single quotes, double quotes etc.

I also considered using <asp:LinkButton> but this only seems to allow
one parameter to be passed to the function.

Surely there must be an very simple solution to this in .Net as it was
extremely easy to do in Classic ASP.

If anyone could propose a solution to this problem I would be very
grateful indeed.

Regards
John
Jul 21 '05 #1
1 11419
Try using a LinkButton.
-mike
MVP

"Fresh Air Rider" <Fr*************@Hotmail.com> wrote in message
news:55**************************@posting.google.c om...
Could anyone please tell me how I can call a function from a hyperlink
in C# ?

Examples of scenarios where this would be useful include :-

Loop through a set of records in a repeater and have a hyperlink to
edit each record by passing it's record id to another page.

Loop through a set of files on a server and have a hyperlink to
download a file via a stream on another page by passing its filename
(this is so that the full path of the file is not revealed to the
user).

ie

I have a function within "Codebehind" (which works fine).

public void DownloadFile( string fname,bool forceDownload)
{
......
......
......
}

I have tried calling the function from the ASP page in various ways
such as :-

<asp:HyperLink NavigateUrl="<%#DownloadFile("test.doc",true)%>">D ownload
file</asp:HyperLink>

This method results in the error "The best overloaded method match for
'System.Convert.ToString(object)' has some invalid arguments"

I have tried various permutations of single quotes, double quotes etc.

I also considered using <asp:LinkButton> but this only seems to allow
one parameter to be passed to the function.

Surely there must be an very simple solution to this in .Net as it was
extremely easy to do in Classic ASP.

If anyone could propose a solution to this problem I would be very
grateful indeed.

Regards
John

Jul 21 '05 #2

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

Similar topics

2
23805
by: sumGirl | last post by:
Is it possible to use a hyperlink to call a vbs sub? I have seen folks using javascript to do this, but I cannot make it work with vbs and I need to. Please no "you should use javascript"...
6
13262
by: NB | last post by:
Hi Is there any way to call up the query design view from code? In my compiled-as-MDE app everything is hidden from end users. However, I want advanced user to have access to the query design...
5
2956
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
5
4497
by: Fresh Air Rider | last post by:
Could anyone please tell me how I can call a function from a hyperlink in C# ? Examples of scenarios where this would be useful include :- Loop through a set of records in a repeater and have...
1
1848
by: D. Shane Fowlkes | last post by:
Hello All. I keep asking for help with this on the www.asp.net forums and nobody seems to be able to help. What I'm trying to accomplish is very simple. I simply want to create a Hyperlink...
1
603
by: Fresh Air Rider | last post by:
Could anyone please tell me how I can call a function from a hyperlink in C# ? Examples of scenarios where this would be useful include :- Loop through a set of records in a repeater and have...
2
4987
by: SAL | last post by:
I would like to create a VB.net function, that builds a dynamic hyperlink using System.Web.UI.WebControls.HyperLink, but I can not find any examples on how to generate a dynamic hyperlink. Has...
2
5559
by: Antonio | last post by:
Hi, I would like to have my TreeNode to call window.close(); without posting back, how can I do that? At the same time, I prefer to have a SelectAction property that allows my TreeNode to appear...
2
2772
by: mdock | last post by:
Hello, I have a javascript grid on my ASP page which displays information about the history of specific units produced in our manufacturing facility. One of the results is the order number on...
0
7237
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,...
0
7349
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5659
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,...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4734
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...
0
3219
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...
0
1572
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 ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.