Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi i need to run function in c# when click ( on click ) event , html link , and send value to this function ??

my code is :
"
<a href='#' runat="server" >
"


and c# code function is :
C#
void myfunction(int ProductID)
       {
           HiddenFieldID.Value = ProductID.ToString();
           Server.Transfer("ProductDetails.aspx");
       }




i try to do like that but there are error ? please help :)
Posted
Comments
Praveen Kumar Upadhyay 20-Dec-14 3:59am    
What is the error, you are getting.
[no name] 20-Dec-14 7:03am    
i got this on my page ?
new Sys.WebForms.Menu({ element: 'NavigationMenu', disappearAfter: 500, orientation: 'horizontal', tabIndex: 0, disabled: false });

use can use ajax for achieving your requirement
use jquery ajax

add jquery libs in <head></head> section
e.g
<script src="../JS/jquery-1.10.2.js" type="text/javascript"></script>
<script src="../JS/jquery-ui-1.10.4.custom.js" type="text/javascript"></script>
<script src="../JS/jquery-ui.js" type="text/javascript"></script>


then
do a ajax call from javascript funtion
e.g
function myfunc(Productid)
{
var url = "/Yourajaxfile.aspx?Productid=" + Productid;
//alert(url);
$.ajax({
type: "POST",
url: url,
success: function (msg) {


},
Error: function (x, e) {
alert("Error Occured");
}
});
}



call javascript function on onclick event of your html code


in ajax page on load
capture value using query string and then pass your method

C# code:-
void myfunction(int ProductID)
{
HiddenFieldID.Value = ProductID.ToString();
Server.Transfer("ProductDetails.aspx");
}
 
Share this answer
 
v2
Hi in asp.net same control available linkbutton you can use easily

< asp:LinkButton Text="Click me!" OnClick="lblClick" runat="server" / >

before using this remove space
 
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