F
Fresh Air Rider
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)%>">Download
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
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)%>">Download
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