473,657 Members | 2,733 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:HyperLin k NavigateUrl="<% #DownloadFile(" test.doc",true) %>">Download
file</asp:HyperLink>

This method results in the error "The best overloaded method match for
'System.Convert .ToString(objec t)' 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 11471
Try using a LinkButton.
-mike
MVP

"Fresh Air Rider" <Fr************ *@Hotmail.com> wrote in message
news:55******** *************** ***@posting.goo gle.com...
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:HyperLin k NavigateUrl="<% #DownloadFile(" test.doc",true) %>">Download
file</asp:HyperLink>

This method results in the error "The best overloaded method match for
'System.Convert .ToString(objec t)' 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
23826
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" answers. Unfortunately I am where I am and I have to use vbs.
6
13288
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 view so they can create, run and export their own query. Another question is: can they be prevented from saving those on-the-fly queries?
5
2966
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 problems with the http://www.mvps.org/access/api/api0002.htm but it only browse to folders.
5
4505
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 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
1
1854
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 Column in a Datagrid and reformat the text output of the column. The helper function seems to be working but the hyperlink column isn't properly being render into html. The actual hyperlink web control is showing up in the html when tested on two...
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 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
2
4991
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 anyone done this before? I do not want to dynamically create my hyperlink on an ASP page, but rather a behind the scenes link that a user can paste into a Word document or Email, as an embedded link that points to a particular file. This would be...
2
5568
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 as hyperlink with hand-cursor when hover. For your information, my TreeView control is on a master page. I have done some tricks but when clicking the node, it does the post-back and my page appears empty with nothing on it except the popup...
2
2798
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 which the unit was shipped. If the unit was not shipped, obviously there is no order number; the default value of this field on the data table is 0. Herein lies the problem; if the order number is 0, I do not want the grid to display anything. If...
0
8306
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7327
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...
1
6164
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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
4152
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...
1
2726
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
1615
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.