如何在JavaSript中使用ASP.NET LinkBut​​ton [英] How to use ASP.NET LinkButton with JavaSript

查看:61
本文介绍了如何在JavaSript中使用ASP.NET LinkBut​​ton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我想将ASP.NET LinkBut​​ton与JavaSript一起使用,

我正在使用没有回发功能的Client CallBack,

我的JavaScript是:

Hi guys,
I want to use ASP.NET LinkButton with JavaSript,

i am using Client CallBack without postback,

my javascript is:

<<pre lang="xml">script type="text/javascript">
function ReceiveBikeColor(colorFile)
{
    // any code here
}







<pre lang="cs">public partial class About : System.Web.UI.Page, ICallbackEventHandler
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string cbRef = ClientScript.GetCallbackEventReference(this, "arg", "ReceiveBikeColor", "context");
        string cbScript = "function GetBikeColor(arg, context) {" + cbRef + "; }";
        ClientScript.RegisterClientScriptBlock(this.GetType(), "GetBikeColor", cbScript, true);
    }

    public string GetCallbackResult()
    {
        //////////
    }
    public void RaiseCallbackEvent(string eventArgument)
    {
        ///////
    }
}




但是在将onclick属性分配给Javascript方法时,如下所示:




but when assign onclick attribute to Javascript method like that:

<asp:LinkButton id="lbtnAddToFavorites" runat="server"  OnClick="GetBikeColor()" >Add to favorites</asp:LinkButton>



它告诉我:

错误"ASP.specifictopic_aspx"不包含"GetBikeColor"的定义

并在使用OnClientClick属性时将其打​​包为Postpack



it tell me that:

Error ''ASP.specifictopic_aspx'' does not contain a definition for ''GetBikeColor''

and when use OnClientClick attribute it casue Postpack

<asp:LinkButton id="lbtnAddToFavorites" runat="server"  OnClientClick="GetBikeColor()" >Add to favorites</asp:LinkButton>

推荐答案

尝试这种方式

try that way

function GetBikeColor()
{
//Some Implementation
return false;
}


<asp:LinkButton id="lbtnAddToFavorites" runat="server"  OnClientClick="return GetBikeColor();" >Add to favorites</asp:LinkButton>


如果您试图在有人单击LinkBut​​ton时调用js函数,则可以使用OnClientClick.

确保定义了函数GetBikeColor并可以访问.

LinkBut​​ton.OnClientClick属性 [ LinkBut​​ton.OnClick方法 [
If you''re trying to call a js function when someone clicks the LinkButton, OnClientClick is the way to go.

Make sure you defined the function GetBikeColor and that it''s accessible.

LinkButton.OnClientClick Property [^]

LinkButton.OnClick Method [^]

Hope this helps!



这是正确的吗?,请使用onclientclick调用javascript.
再次尝试.祝您好运.
问候,
shefeek
Hi,
is this correct?,use onclientclick to call javascript.
try once again.best of luck.
regards,
shefeek


这篇关于如何在JavaSript中使用ASP.NET LinkBut​​ton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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