从ASP页面调用函数背后的代码 [英] Call a code behind function from ASP page

查看:53
本文介绍了从ASP页面调用函数背后的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我一直在尝试在C#函数后面调用代码,即链接href中的Button click().我尝试了几种解决方案,甚至创建了一个名为按钮单击功能的javascript函数,并且在href中我调用了javascript函数,但到目前为止仍未找到任何解决方案.页面上什么都没有发生,所以在我实际调用函数背后的代码之前,这是我的事:

ASP页面:

javascript:

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:

function click() 
{
   alert("HEY");

}



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



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


是否有人作为解决方案要么从href调用函数背后的代码,要么仅从href调用javascript函数?

谢谢

已从答案中移除:
javascript dopostback实际上使我前进了一些.我遵循此页面中的示例:
http://wiki.asp.net/page.aspx/1082/dopostback-function/ [< ^ ]
该页面正在执行回发,但未输入codebehind函数.
仍然需要帮助!



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!

推荐答案

您好,

您可以从href调用javascript函数.使用以下代码:

Javascript:
Hello,

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

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



HTML:



HTML:

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



要在函数后面调用代码,请参考以下链接:

http://www.codedigest.com/Articles/ASPNET/314_Multiple_Ways_to_Call_Javascript_Function_from_ASPNetasp <"http://www.codedigest.com/Articles/ASPNET/314_Multiple_Ways_to_Call_Javascript_Function_from_CodeBehind_in_ASPNet.aspx" target ="_ blank" title ="New Window"> ^ ]

而这个:

http://msdn.microsoft.com/hi-in/magazine/cc163941(en -us).aspx [ ^ ]



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[^]




如果要从javascript调用函数代码,而不是在javascript do_postback方法上进行搜索.您会找到自己的方式.
Hi,

If you want to call function code behind from javascript than search on javascript do_postback method. You will get your way.


//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>


这篇关于从ASP页面调用函数背后的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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