Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何将JQuery嵌入到自定义服务器控件中_.net_Jquery_Custom Server Controls - Fatal编程技术网

.net 如何将JQuery嵌入到自定义服务器控件中

.net 如何将JQuery嵌入到自定义服务器控件中,.net,jquery,custom-server-controls,.net,Jquery,Custom Server Controls,我正在编写一个服务器控件,它是一个带有建议的搜索框,当用户开始键入时,会出现匹配的单词供他们选择。我正在使用jquery和C 当我在测试的页面上包含jquery库时,该控件工作正常。但是,当我尝试将库嵌入DLL时,它将不起作用 我已尝试完全嵌入它并注册脚本: ClientScriptManager manager = this.Page.ClientScript; manager.RegisterClientScriptResource(typeof(Search), jqueryResourc

我正在编写一个服务器控件,它是一个带有建议的搜索框,当用户开始键入时,会出现匹配的单词供他们选择。我正在使用jquery和C

当我在测试的页面上包含jquery库时,该控件工作正常。但是,当我尝试将库嵌入DLL时,它将不起作用

我已尝试完全嵌入它并注册脚本:

ClientScriptManager manager = this.Page.ClientScript;
manager.RegisterClientScriptResource(typeof(Search), jqueryResource); //jqueryResource= SearchControl.javascript.jquery.js 
我还尝试在包含jquery的页面标题中添加一个标记:

string javascriptUrl = manager.GetWebResourceUrl(typeof(Search), jqueryResource); 
LiteralControl jquery = new LiteralControl(string.Format(javascriptInclude, jqueryUrl));
Page.Header.Controls.Add(jquery);
当试图从控件获取信息时,这两种方法都会导致javascript错误

var params = $("#searchBox").val(); //called on keyup when typing in textbox
以前有人这样做过吗?可能吗?有人能解释一下吗

PS:程序集已在AssemblyInfo.cs文件中注册。

编辑:重新阅读您的问题,并意识到我刚刚重复了您的操作。然而,这是我的实现,它按预期工作:

您需要使用RegisterClientScriptResource。只需在控件的PreRender事件中调用取自my ScriptRegisterHelper静态类的以下代码段:

/// <summary>
/// Registers the jQuery client script to the page.
/// </summary>
/// <param name="cs">The ClientScriptManager to assign the script to.</param>
internal static void RegisterJQuery(ClientScriptManager cs)
{
    cs.RegisterClientScriptResource(typeof(ScriptRegisterHelper), 
        "MyProject.Resources.jquery.js");
}
和AssemblyInfo文件:

[assembly: System.Web.UI.WebResource("MyProject.Resources.jquery.js", "text/javascript")]

这正是我最初做的,但它仍然不起作用。然后,当我继续思考的时候,有些东西咔哒作响。我查看了脚本文件构建操作,猜猜看是什么?没错,我忘了将这个设置为嵌入式资源,你认为它在注册程序集时会这样做。不管怎么说,它现在很有魅力。谢谢你的帮助!我知道我也应该提到这一点!谢谢你提醒我如何设置要嵌入的资源。这让我发疯。
[assembly: System.Web.UI.WebResource("MyProject.Resources.jquery.js", "text/javascript")]