Put Script Manager in master page - asp.net

is it right to put script manager in master page ?

It isn't wrong, as such.
Really depends on your requirements.
If you need to use scripts in several pages that use the same master page, use ScriptManager in the master page.
Just keep in mind that you can only have one ScriptManager in the whole loaded page, so you can't add one in content pages as well.
See this article on MSDN for an example (Using the ASP.NET UpdatePanel Control with Master Pages).

Related

Master Pages over User Controls

An interview question someone asked me but I was left stumped.
If you can implement user controls inside a normal aspx page, what is the use of a master page then ?
A master page defines a layout template. You put things like styling and scripts in the master page, then call them in any page derived from that master.
It's a way of being able to split presentation out from functionality, and things you need everywhere can be put in the masterpage.

Reload only Content Pages Inside the Masterpage

I have more than 100pages in my project & a single master page for all this. My masterpage has links to different pages. I want to change only the ContentPages( Child Pages) & my masterpage should not get reloaded.
For Example:
My Master page is : SiteMaster.master
Child Page1: Add.aspx
Child Page2: Sub.aspx
When I execute, Add.aspx comes inside the SiteMaster.master. Know, When I click the sub.aspx link inside the Add.aspx, only add.aspx page should be changed & sub.aspx must be loaded. I don't want to reload the master page.
If possible, please post some examples or links.
Your expected behavior is not exactly how master pages work. There may be ways to achieve a no postback solution in this scenario but the easiest one would be to use an <IFrame /> (which is usually frowned upon)
Master page is part of your pages. It's not loading separately.
Simple explanation:
ASP.NET engine takes your aspx and puts it inside the master page and then renders it as one page, then serves it to user.
If this is not what you want and you want that only content of your master page be loaded, then you should not use master pages at all! It's against nature of master pages. they act like skins for aspx pages.
Search for HTML IFrame tag and don't use master page.
P.S: IFrames are not used widely in this days.

Loading ScriptManager only once either from Master page or Content page

I have an web application of 200 web pages and all has a single master page. Most of the content pages use AJAX controls so most of content pages has its own ScriptManager. Now I have a requirement to add a link with HoverMenuExtender control and for that I need to put ScriptManager in the Master page, but it is working only in the content pages where there is not ScriptManager.
All the other content pages which has ScriptManager throws the error Only one instance of a ScriptManager can be added to the page. I don't want to work on most of the content pages again to remove ScriptManager.
Is there any easy way to do this something like coding in Master page which decides if there is already ScriptManager already, then don't load it.
Take a look at ScriptManagerProxy. This is what I think you need.

Web User Controls, Javascript and Script Managers

Is there a way to only add a script manager to your Web User Control if there is not one already on the page (on the main page or if you are using the Web User Control multiple times)?
Same question about adding javascript files to the page, many times I have controls that add the javascript into the head of the page for the control.
Regarding ScriptManager:
I would use master pages, and include the script manager on your master page. Alternatively, if you have something like Header.ascx which you know is included on every page, you could put it there also.
Regarding javascript files:
Use the ClientScriptManager.RegisterStartupScript method to include javascript on your page. It will not produce duplicates if they share the same key name parameter.
http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx

ASP.NET master pages order of adding scripts

I have a master page that adds the jquery library via a registerclientscriptinclude:
Page.ClientScript.RegisterClientScriptInclude(this.GetType(),
"JQuery",
Page.ResolveUrl("~/Scripts/jquery-1.2.6.min.js"));
In a page that uses that master page I want to include a script that depends on jquery:
Page.ClientScript.RegisterClientScriptInclude(this.GetType(),
"jqplugin1",
Page.ResolveUrl("~/Scripts/jquery.plugin1.compressed.js"));
This causes a problem because the page's client scripts are written first and then the master pages client scripts (causing the plugin to complain that "jquery" is undefined).
Is there anyway to control the ordering of client script includes? Alternatively any recommendation on how best to control this (temporarily the master page is just including everything... but that's not going to work long term).
since master page is like a control embedded in a page, you can add these scripts towards the end of the page cycle, the control would fire first and then page, so your page would be fine.
You could re-include the jQuery library in the page, if it's already there it will simply override it, if not it will be added.

Resources