Click here to Skip to main content
15,902,817 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello I've been trying to call a code behind C# function, that is a Button click() from a link href. I've tried several solutions, even created a javascript function that called the button click function, and in the href I call the javascript function but still so far haven't found any solution. Nothing is happening in the page so before I can actually call the code behind function, here's my deal:

ASP Page:

javascript:
C#
function click() 
{
   alert("HEY");

}


HREF:
<a href="#" class="button" onclick="javascript:click();"><span>Cards</span</a>

or

<a href="javascript:void(0)" class="button" onclick="click()"><span>Cards</span</a>


Does anyone as any solution either to call a code behind function from a href, or to just call a javascript function from href?

thank you

Moved from answer:
The javascript dopostback actually made me advance a little more. I follow the example in this page:
http://wiki.asp.net/page.aspx/1082/dopostback-function/[^]
The page is doing the postback but is not entering the codebehind function.
Still need help!
Posted
Updated 2-Feb-11 2:40am
v3

Hello,

You can call a javascript function from href. Use the following code:

Javascript:
C#
function Hello() {
    alert("Yor code goes here....");
}


HTML:
<a href="#" onclick="javascript:Hello();"><span>HELLO....</span></a>


For calling code behind function, please refer the following link:

http://www.codedigest.com/Articles/ASPNET/314_Multiple_Ways_to_Call_Javascript_Function_from_CodeBehind_in_ASPNet.aspx[^]

and this:

http://msdn.microsoft.com/hi-in/magazine/cc163941(en-us).aspx[^]
 
Share this answer
 
v2
Comments
sapien4u 2-Feb-11 7:49am    
How is it working now?
Is it fine?
Hi,

If you want to call function code behind from javascript than search on javascript do_postback method. You will get your way.
 
Share this answer
 
C#
//If you are databinding then
<a href="<%# GetURL(Eval("VideoCategoryID")) %>">

//If not

<a href='<%= GetURL(Eval("VideoCategoryID")) %>'>

//method from codebehind
protected string GetURL()
        {
            string path = "codeproject.com";
            return path;
            
        }</a>
 
Share this answer
 
Hi

Try this Code .

XML
<a href="javascript:void(bla();return true)">
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900