问题描述
目前,我使用以下方法调用我的JavaScript函数:
ScriptManager.RegisterClientScriptBlock(this,typeof(Page),Guid。 NewGuid()。ToString(),$(function(){$。jGrowl('Hello World');});,true);
完美无缺!即使使用母版页和更新面板,它也能按预期工作。
然而,当我尝试在嵌入在被调用页面中的用户控件中执行相同操作时使用jQuery thickbox,它不起作用!
有谁知道如何解决这个问题?
ScriptManager.RegisterClientScriptBlock(this.Page,typeof(UpdatePanel) ,Guid.NewGuid()。ToString(),$(function(){$。jGrowl('Hello World');});,true);
正如@Joel所提到的那样,我用作参数的类型存在问题对于该函数。
注意:如果您使用的是厚箱,可能是您没有在包含用户控件的页面中使用母版页。因此,jQuery也需要在该页面中引用,因为母版页没有参与厚盒。
Currently, I am calling my JavaScript functions using:
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), Guid.NewGuid().ToString(), "$(function(){$.jGrowl('Hello World');});", true);
It works perfectly! Even using master page and update panel it works as expected.
However, when I try to do the same in a user control that is embedded in a page that is being called with a jQuery thickbox, it does not work!
Does anyone know how to solve this issue?
This solved the problem:
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), Guid.NewGuid().ToString(), "$(function(){$.jGrowl('Hello World');});", true);
As it was mentioned by @Joel, there was a problem with the type I was using as a parameter for the function.
Note: If you're using a thickbox, probably you are not using the master page in the page that contains the user control. Therefore, jQuery needs also to be referenced in that page since the master page is not partaking in the thickbox.
这篇关于在用户控件中从codebehind C#调用JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!