JQuery in ASP.NET UserControl

Scenario 1

The page contains only the MultiSelect user control. Here jQuery works well.

Scenario 2

I moved the MultiSelect user control to a project where we use the master pages and the UpdatePanel. Page Hierarchy

Master Page β†’ Content Page β†’ Div β†’ MultiSelect User Management

Here jQuery does not work.

About MultiSelect User Management

The control has a link to a jQuery file, and it invokes a lot of groupings. Therefore, if I click the "Group Header" button, all child flags will be selected.

My inquiries

  • Why doesn't jQuery work in Scenario 1?

  • Where is the best place to link the link to the jQuery file, on the main page, on the content page, or in the UserControl itself.

  • I heard that if we use UpdatePanel, we also need to use PageRequestManager.

  • Writing JavaScript code in a Code Behind file will solve the problem?


Well. When using jQuery in an ASP.NET user control, we must do the following (all steps are optional).

a. You can write the code in the code behind the file. There you should also use PageRequestManager .

b. You can put the jQuery link on the main page.

+4
source share
2 answers

Maybe your JQUERY is contrary to AJAX Javascript. If you put our jquery in usercontrol check its path. If usercontrol is in the same folder, then the path should not correspond to user management. The path always corresponds to the main page or parent page. You can test your java script Firebug error or if you have the latest fire fox, press ctrl + shift + k. refresh your page and check the function why it doesn’t work. you will find the java script error.

+3
source

I have this problem, but with a lot of tests, this problem can be solved.

The best place to define and import css and jQuery files in asp pages and should not be added to ascx (user control).

The update panel with jQuery and Javascript has a conflict, so if you use jQuery and Javascript in your usercontrol, as well as me, remove the update panel, however you can do this:

  <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always" RenderMode="Block"> 

in the user control.

And install Script Manager on the main page or asp page containing user controls.

According to your help for using PageRequestManager, I try, but the scripts generated for the page encountered an update panel and crash.

+2
source

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


All Articles