首页 \ 问答 \ Jquery用户控件(Jquery user control)

Jquery用户控件(Jquery user control)

我有一个问题,没有在asp用户控件中加载jquery。

我只想在单击复选框时添加click事件。

这是我的javascript文件

$(document).ready(function() {
    var arr = jQuery(":checkbox[id*='drpAccountType']");
    for (i = 0; i < arr.length; i += 1) {
        $("#" + arr[i].id).click(function() { alert(this.id) });
    }
});
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

用户控制预渲染事件:

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        ScriptManager.RegisterClientScriptInclude(Me, Me.GetType, "CheckboxdropdownScript", ResolveUrl("~/Scripts/CheckBoxDropDown.js"))
End Sub

脚本加载正常,但jQuery的任何用法都返回undefined。 然后只有在加载页面时,我才能在firebug中为commande行执行相同的代码。 jquery库加载在母版页中。

每当我在asp用户控件中使用jquery时,我总会发现问题,而且我总是不得不破解它以使其工作。 我尝试了stackoverflow中的所有条目,但我从来没有找到一个作为一般解决方案。

有没有人发现一个简单的解决方案,使用jquery与母版页,用户控制在asp.net我会很感激,如果有人可以分享这些有价值的信息。

我的经理即将从应用程序中删除jquery,因为我们总是花费大量时间来找到一个解决方法,让它与用户控件一起工作。

请帮助,我喜欢jquery,我真的想将它用于客户端脚本。

最好的祝福


I have a problem with jquery not loaded in an asp user control.

I want simply to add the click event when a checkbox is clicked.

Here is my javascript file

$(document).ready(function() {
    var arr = jQuery(":checkbox[id*='drpAccountType']");
    for (i = 0; i < arr.length; i += 1) {
        $("#" + arr[i].id).click(function() { alert(this.id) });
    }
});
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

The user control pre render events:

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        ScriptManager.RegisterClientScriptInclude(Me, Me.GetType, "CheckboxdropdownScript", ResolveUrl("~/Scripts/CheckBoxDropDown.js"))
End Sub

the script is loaded fine but any usage of jQuery return undefined. Then only when the page is loaded I can excute the same code for the commande line in firebug. The jquery library is loaded in the master page.

Whenever I'm using jquery within an asp user control I always find problems, and I always have to hack around to get it to work. I try all the entries in stackoverflow but I never found a one as general solution.

did any one found a simple solution to use jquery with master pages, user control in asp.net I would appreciate if someone can share such valuable information.

My manager is about to drop jquery from the application as we always waist lot of time just to find a workaround to have it to work with user controls.

Please help, I like jquery and I really want to use it for client script.

best regards


原文:https://stackoverflow.com/questions/967400
更新时间:2023-06-22 06:06

最满意答案

你实际上想要做的是读一个论点。 你可以使用process.argv 。 更多关于在这里找到的全局节点变量process

当你的脚本标签看起来像这样:

"scripts": {
  "my-command": "my-script.js"
}

当你的脚本文件看起来像这样:

console.log( process.argv );

然后所有要做的就是用npmyarn运行你的命令。

npm run my-command <your-argument e.g. file.js>

如果您想将它传递给另一个命令,您可以使用require( 'child_process' ).exec . require( 'child_process' ).exec来调用该命令。 关于这个的一个很好的例子可以在这里找到。


What you actually want to do is reading an argument. You can use process.argv for that. More about the global node variable process to be found here.

When your script tag looks something like this:

"scripts": {
  "my-command": "my-script.js"
}

When your script file looks something like this:

console.log( process.argv );

Then all is left to do is run your command with npm or yarn.

npm run my-command <your-argument e.g. file.js>

If you want to pass it to another command, you can call that command with a require( 'child_process' ).exec. A good example about that can be found here.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。