简体   繁体   English

从aspx页面在用户控件中调用jQuery函数

[英]Calling a jquery function in a usercontrol from an aspx page

This is my first encounter with User Controls. 这是我第一次接触用户控件。

I have a user control that contains a jQuery function called Animate(). 我有一个用户控件,其中包含一个称为Animate()的jQuery函数。 I want to call that function from an aspx page that contains the user control. 我想从包含用户控件的aspx页面调用该函数。 Is that possible? 那可能吗?

When I click the button in the following code the function is not fired and no error. 当我单击以下代码中的按钮时,该功能未触发且没有错误。 What am I missing? 我想念什么?

Upload_Animation.ascx Upload_Animation.ascx

<head>
<script>
function AnimateGif() {
    // do some stuff    
}
</script>
</head>
<body>User Control</body>

aspx page aspx页面

<head runat="server">
<uc:UploadAnimation ID="uc1" runat="server"/>
</head>
<body>
<form id="form1" runat="server">
<div> 
<asp:Button OnClientClick="AnimateGif();" runat="server" Text="Do stuff" OnClick="btn_Click"/>

</div>
</form>
</body>

web.config web.config

<controls>
<add tagPrefix="uc" src="~/UserControls/Upload_Animation.ascx" tagName="UploadAnimation" />
</controls>

First of all, I cannot see any JQuery code in your source example. 首先,在您的源示例中看不到任何JQuery代码。 As I can see (correct me if I'm wrong), you are trying to call client Javascript function that is declared as Animate() and you are calling as AnimateGif(); 如我所见(如果我错了,请纠正我),您正在尝试调用声明为Animate()的客户端Javascript函数,而您正在调用AnimateGif(); Try to correct the name of the calling function to match the declared name. 尝试更正调用函数的名称以匹配声明的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM