Rauf
Rauf

Reputation: 12842

jQuery in ASP.NET UserControl

Scenario 1

The page contains nothing but only the 'MultiSelect' user control. Here, jQuery is working well.

Scenario 2

I moved the 'MultiSelect' user control to a project where we use master pages and UpdatePanel. The hierarchy of the page is

Master Page --> Content Page --> Div --> MultiSelect user control

Here jQuery is not working.

About MultiSelect user control

The control having a reference to jQuery file and it contails lot of check boxes grouped. So if I click on group header check box, all the child check boxes will get selected.

My queries are

  1. Why jQuery does not work in Scenario 1 ?

  2. Where is the best place to link the reference to the jQuery file, in Master Page, in Content Page, or in UserControl itself.

  3. I heard about if we use UpdatePanel, we need to use PageRequestManager too.

  4. Writing JavaScript code in Code Behind file will solve the issues ?


Well. While using jQuery in ASP.NET User Control, we have to do the following(all the steps are not mandatory)..

a. You may write code in code behind file. There you have to use PageRequestManager too.

b. You may put reference to jQuery in Master Page.

Upvotes: 4

Views: 803

Answers (2)

Harry Sarshogh
Harry Sarshogh

Reputation: 2197

I have this problem but with lot of test can solved it this details.

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

Update panel with jQuery and Javascript have conflict so if you use jQuery and Javascript in your usercontrol as well as me, delete update panel nevertheless you can this :

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

in user control.

And set Script Manager in your master page or asp page that included user controls.

In accordance your help for use PageRequestManager, I try for it, but scripts which generated for page have conflicted with update panel and crashing it.

Upvotes: 2

Ashfaq Shaikh
Ashfaq Shaikh

Reputation: 1668

May be your JQUERY is conflicted with AJAX Javascript. If you have put our jquery in usercontrol check its path. If the usercontrol in one folder then the path must not according to user control. A path always according to master page or parent page. You can test you java script error by Firebug or if you have latest fire fox press ctrl+shift+k. the refresh your page and check you function why it is not working. you will find the Java script error.

Upvotes: 3

Related Questions