JQuery user control

I have a problem with jquery not loaded into an asp user element.

I want to just add a click event when I click on the checkbox.

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(); 

User Management Pre-Rendering 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 loads fine, but any use of jQuery returns undefined. Then only when loading the page can I release the same code for the command line in firebug. The jquery library is loading on the main page.

Whenever I use jquery in an asp user element, I always find problems, and I always have to crack it to make it work. I am trying to execute all the entries in stackoverflow, but I never found it as a general solution.

Has anyone found a simple solution for using jquery with main pages, user management in asp.net I would appreciate it if someone could share such valuable information.

My manager is going to remove jquery from the application, since we always take a lot of time to find a workaround for it to work with user controls.

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

Best wishes

+4
source share
2 answers

your script can be inserted into the page in front of the jquery library. (You can verify this by checking the HTML output on your page.)

When script files execute JS inline, and especially when it depends on other libraries, it is safer to use RegisterStartupScript rather than RegisterClientScriptInclude . If you use this RegisterStartupScript overload , you can create a link to the same external JS file and it will work in the right place.

Alternatively, you can use the <asp:ScriptReference/> tags in ScriptManagerProxy in a user control, rather than registering the script in Page_Load or Page_Init; in my experience, these scripts are added after the scripts from the main page.

+5
source

this is not a direct answer, but here are some ASP.net jQuery controls that may help:

http://clipperhouse.com/jQuery/

(See the callback bit.)

Also, you may not need the "for" loop if you just pass all your flags to the class name and use it as a selector.

+1
source

Source: https://habr.com/ru/post/1285937/


All Articles