Wednesday, March 28, 2012

ASP.NET AJAX ScriptManager

Hi,

I am a total newbee to whole AJAX as well as Javascripting in general. I just installed the ASP.NET AJAX Extensions and Toolkit and I was watching couple of videos on this site. The first video mentioned something about only having 1 instance of the ScriptManager..?

This is how we develop at the moment. We have a general page on which we just drop ASCX (User controls). Each control has thus it's own Load event and all along with it's own design with few controls in it.

So where do I need to drop this ScriptManager control? On every ASCX file?

Cheers,

Nirav Patel

Nirav,

If you have a MasterPage in your website, and you'll be using AJAX on every page then the MasterPage is theonly place where you would drop the ScriptManager control.

Otherwise, you would drop the ScriptManager control to your "general".aspx page.

Let me know if you need more info.


Thanks for a quick reply.

We don't have a master page type of setup nor we have a general page.

What we have is a template where we define section of the page like "header", "content" (this might have "left" for menu, "middle" for contect, "right" for ads), "footer". Then ASCX are inserted into those sections as required.

So can I just modify the template and add the ScriptManager at the top?

Cheers :)


niravpatel:

This is how we develop at the moment. We have ageneral page on which we just drop ASCX (User controls).

The term 'general page' I used because you used it in your original post.

The fact is that there can only be one instance of ScriptManager control per page. This is why you must place the ScriptManager control in a parent .aspx page. If the user controls need to reference a script or a service, then you can use ScriptManagerProxy control in your .ascx controls.


Hiniravpatel,

You should add it after the <form> tag.

<html>
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"></asp:ScriptManager>
</form>
</body>
</html>

Otherwise you will get the following error:

Server Error in '/' Application.
------------------------

Control 'ScriptManager1' of type 'ScriptManager' must be placed inside a form tag with runat=server.

Cheers,
Al

No comments:

Post a Comment