Ajax Script Manager and Master Pages
Asked Answered
S

5

9

I'm building a new website and want to use Ajax controls.

Do I need to put a ScriptManager control on both the MasterPage and on each content page? or Just on the MasterPage?(or just on the content page?)

Shulman answered 19/2, 2009 at 21:12 Comment(0)
R
6

You are only allowed to have one ScriptManager. You can have it on either. Having it on the master page saves you the task of adding it on content pages. However, writing custom script within the script manager is only possible if you have it in the content pages. As stated below, having two ScriptManagers throws an error on loading the page.

Relativity answered 19/2, 2009 at 21:14 Comment(0)
E
13

Content pages or MasterPages can only have one ScriptManager control on them. If you have a ScriptManager control on your MasterPage, you can drop a ScriptManagerProxy control onto your content pages to use any given specific ASP.NET AJAX functionality like this, for example:

<asp:Content ID="Content1" ContentPlaceHolderID="BodyContent" runat="server">
    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
        <Services>
            <asp:ServiceReference Path="~/MyWebServices/YourCoolWebService.asmx" />
        </Services>
    </asp:ScriptManagerProxy>

    <%-- more content stuff goes here --%>
<asp:Content>
Everard answered 19/2, 2009 at 21:51 Comment(2)
What if I'm just using one of the Ajax controls in the content page...do I still need the ScriptManagerProxy control on the control page?Shulman
If you just want to use ASP.NET AJAX controls on your content page, then no need for the ScriptManagerProxy.Everard
R
6

You are only allowed to have one ScriptManager. You can have it on either. Having it on the master page saves you the task of adding it on content pages. However, writing custom script within the script manager is only possible if you have it in the content pages. As stated below, having two ScriptManagers throws an error on loading the page.

Relativity answered 19/2, 2009 at 21:14 Comment(0)
C
1

Just the master page. Unless you are going to have custom scripts like mentioned above, I would recommend just putting it on the Master Page so that you do not have to put it on every page that is going to use an ajax control.

If you have it on both it throws an error saying that you can only have one scriptmanager/page

Chura answered 19/2, 2009 at 21:14 Comment(0)
H
1

What functionality are you looking for? Chances are you will be able to do just as much or more, but with a much lighter footprint, better performing code and better control over what's actually happening if you use jQuery instead. Check it out!

Hamamatsu answered 19/2, 2009 at 21:20 Comment(3)
I want to use the Ajax ControlsShulman
If you r e a l l y want to use Ajax Controls, I'm not going to stop you. But if what you want is to get some of the f u n c t i o n a l i t y that Ajax Controls offer, I think you will be surprised to see that it's even easier to do the same thing - better - with jQuery.Hamamatsu
Using ajax controls is good but there may be instances when jquery would be very useful. If you have never used it before I would highly recommend checking it out. If you are going to be writing any javascript at all it is a life saver.Chura
M
1

jQuery vs ASP.NET AJAX is not an "either-or question". Although they have overlapping functionality, they are very diff, and I use both daily depending on task. Use jQuery when possible - but MS AJAX adds a ton of ASP.NET convenience functionality.

Menorca answered 19/10, 2009 at 5:34 Comment(2)
this should be changed to a comment on Tomas Lycken's answerCandis
For regular web applications (ASP.NET, J2EE, PHP, etc.), I have found jQuery to be a ton of help. I have just begun considering the use of Ajax in my SharePoint web parts, in web part pages. From this perspective, which is better - ASP.NET AJAX or jQuery?Cralg

© 2022 - 2024 — McMap. All rights reserved.