在html asp c#代码后面的单击链接上运行方法? [英] run method on click link in html asp c# code behind ?

查看:86
本文介绍了在html asp c#代码后面的单击链接上运行方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
i需要在c#中运行函数,点击(点击)事件,html链接,并向这个函数发送值?



my代码是:

< a href ='#'runat =server>






和c#代码功能是:

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 :

void myfunction(int ProductID)
       {
           HiddenFieldID.Value = ProductID.ToString();
           Server.Transfer("ProductDetails.aspx");
       }









i尝试这样做但是有错误吗?请帮助:)





i try to do like that but there are error ? please help :)

推荐答案

使用可以使用ajax来实现你的要求

使用jquery ajax



在< head>< / head>中添加jquery库部分

例如

< script src =../ JS / jquery-1.10.2.jstype =text / javascript>< / script> ;

< script src =../ JS / jquery-ui-1.10.4.custom.jstype =text / javascript>< / script>

< script src =../ JS / jquery-ui.jstype =text / javascript>< / script>





然后

从javascript函数做ajax调用

例如

函数myfunc(Productid)

{

var url =/ Yourajaxfile.aspx?Productid =+ Productid;

// alert(url);
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({

类型:POST,

url:url,

成功:功能(msg){





},

错误:函数(x,e){

alert(错误发布);

}

});

}







在html代码的onclick事件上调用javascript函数




ajax中的
页面加载

使用查询字符串捕获值然后传递你的方法



C#代码: -

无效myfunction(int ProductID)

{

HiddenFieldID.Value = ProductID.ToString();

Server.Transfer(ProductDetails.aspx) ;

}
.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");
}


Hi
在asp.net中同样的控件可用链接按钮你可以轻松使用



< asp:LinkBut​​ton Text =点击我!在使用此删除空格之前,OnClick =lblClickrunat =server/>



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


这篇关于在html asp c#代码后面的单击链接上运行方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆