473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 11389
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...

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.