Showing posts with label scriptmanager. Show all posts
Showing posts with label scriptmanager. Show all posts

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

Monday, March 26, 2012

ASP.NET AJAX Beta 1 and Adding a ScriptManager dynamically

I just upgraded to ASP.NET AJAX Beta 1 from the July CTP and am having problems with dynamically adding a ScriptManager to my page. It was working fine before I upgraded.

What I was doing before was this: I created a new class that inherited from Page and in the constructor of that class I created a ScriptManager object and add it to the Controls collection. That was working fine before. Since the upgrade, I am getting the following error when trying to add the ScriptManager in the constructor:

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

So I tried adding the ScriptManager to the Form.Controls collection during the page's Init event, but then I got this error because I have an UpdatePanel on the page:

The control with ID 'UpdatePanel1' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

So my question is how do I dynamically add a ScriptManager to the Form.Controls collection before an AJAX control checks for it?

Thanks!

hello.

well, you must add it before the updatepanel is added to the page. try using the preinit event and let us know if it works.


I tried to add it to the page during the PreInit event as well, since the AJAX controls apparently verify that a ScriptManager is on the page between the PreInit and Init events. Unfortuantly during the PreInit event the Form property of the page has not been created yet. So if I add the ScriptManager to the page's Controls collection as opposed to the Form.Controls collection during the PreInit event I get the same error that I stated above:

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

Do you see any way around this?

Thanks for your response!


hello.

hum...can you post a small demo page which reproduces the problem while adding the scritpmanager dynamicaly?

thanks.


Yeah sure. Here is a very small example that shows the problem I am having. If I try to add the ScriptManager in the page's constructor then I get the error message about it having to be in between the page's form tags. If I create the ScriptManager during the PreInit event I get an error that says the UpdatePanel needs a ScriptManager. By the way, the project I created for this demo was from the ASP.NET AJAX CTP-Enabled Web Site template.

ASPX Page:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Script Manager Test</title></head><body> <form id="form1" runat="server"> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> Testing... </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>
Code Behind:
 
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using Microsoft.Web.UI;public partialclass _Default : Page {public _Default() {//This tells me the ScriptManger must be in between the Form tags //if (ScriptManager.GetCurrent(this.Page) == null) //{ // ScriptManager Manager = new ScriptManager(); // Manager.EnablePartialRendering = true; // this.Controls.Add(Manager); //} }protected override void OnPreInit(EventArgs e) {if (ScriptManager.GetCurrent(this.Page) ==null) { ScriptManager Manager =new ScriptManager(); Manager.EnablePartialRendering =true;this.Controls.Add(Manager); }base.OnPreInit(e); }}


Try this:

if (ScriptManager.GetCurrent(this.Page) ==null)
{
ScriptManager Manager =new ScriptManager();

Manager.ID = "SM";
Manager.EnablePartialRendering =true;
this.Controls.Add(Manager);
}


Actually, you'll need to ensure that the ScriptManager is first in the page. For example:

<%@.PageLanguage="C#"AutoEventWireup="true" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headid="Head1"runat="server">

<title>Script Manager Test</title>

</head>

<scriptrunat="server">

protectedoverridevoid OnPreInit(EventArgs e) {

if (ScriptManager.GetCurrent(this.Page) ==null) {

ScriptManager Manager =newScriptManager();

Manager.EnablePartialRendering =true;

SMPlaceHolder.Controls.Add(Manager);

}

base.OnPreInit(e);

}

protectedvoid trigger_Click(object sender,EventArgs e) {

label.Text ="Async post";

}

</script>

<body>

<formid="form1"runat="server">

<div>

<asp:PlaceHolderID="SMPlaceHolder"runat="server"/>

<asp:Buttonrunat="server"Text="Click"ID="trigger"OnClick="trigger_Click"/>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<Triggers>

<asp:AsyncPostBackTriggerControlID="trigger"/>

</Triggers>

<ContentTemplate>

<asp:Labelrunat="server"Text="Get"id="label"/>

</ContentTemplate>

</asp:UpdatePanel>

</div>

</form>

</body>

</html>


That did not fix the problem. It still gives me the following error:

The control with ID 'UpdatePanel1' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

If I remove the UpdatePanel from the page it then gives me this error message:

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


Thanks, SimonCal, that worked to add the PlaceHolder and then add the ScriptManager to it, but that defeats the whole purpose of what I am trying to accomplish. I want to create a base class that inherits the Page class and have the ScriptManager automatically added. That way I can create a new page that inherits my base class and not have to worry about adding the ScriptManager manually every time. Before the beta came out I could add the ScriptManager to the page's Controls collection and it worked perfectly. Now the ScriptManager has to be in the form tags. Is there anyway to accomplish this?

Thanks for your help.


If you have to do it in a generic way from a base class - you can try the following

<%@.PageLanguage="C#"AutoEventWireup="true" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headid="Head1"runat="server">

<title>Script Manager Test</title>

</head>

<scriptrunat="server">

protectedoverridevoid OnPreInit(EventArgs e) {

if (ScriptManager.GetCurrent(this.Page) ==null) {

ScriptManager Manager =newScriptManager();

Manager.EnablePartialRendering =true;

foreach (Control cinthis.Controls)

{

if (cisHtmlForm)

form1.Controls.AddAt(0, Manager);

}

}

base.OnPreInit(e);

}

protectedvoid trigger_Click(object sender,EventArgs e) {

label.Text ="Async post";

}

</script>

<body>

<formid="form1"runat="server">

<div>

<asp:Buttonrunat="server"Text="Click"ID="trigger"OnClick="trigger_Click"/>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<Triggers>

<asp:AsyncPostBackTriggerControlID="trigger"/>

</Triggers>

<ContentTemplate>

<asp:Labelrunat="server"Text="Get"id="label"/></ContentTemplate>

</asp:UpdatePanel>

</div>

</form>

</body>

</html>

Thanks,

Kashif


That did the trick! That's exactly what I was looking for. Thank you very much, kashif!

How do you do this from inside a control? Like.....check to see if its there, then if its not then place it on the page that contains you Atlas control...?


protectedoverridevoid OnPreInit(EventArgs e)

{

if (ScriptManager.GetCurrent(this.Page) ==null)

{

ScriptManager Manager =newScriptManager();

Manager.EnablePartialRendering =true;

foreach (Control cinthis.Controls)

{

if (cisHtmlForm)

{

c.Controls.AddAt(0, Manager);

}

}

}

base.OnPreInit(e);

}

use this code in base class

don't write code in html file

don't hardcode form name in code

thank u


Similar thread:

Is it possible to add a ScriptManager to a page dynamically?

asp.net ajax 2.0 beta 2 error

hi..

i am using asp.net ajax 2.0 beta 2, with scriptManager with any ajax control in the control tool kit, and i get this error:

Sys.WebForms.PageRequestManager._initialize(

'ScriptManager1', document.getElementById('form1'));

'sys' is undefined.

when i get back and use atlas dll, instead of Microsoft.Web.Extensions dll, everything is ok...

why is that?

Hi ya,

I had similar problem two weeks ago. It was that my web site was not properly migrated to an ajax enabled web site. You need to modify your web config to be able to migrate it properly.

http://ajax.asp.net/files/Migration_Guide.doc

here is a document how you should do that.

Cheerz,

Yani

Asp.Net Ajax 1.0 goes odd with MapXtreme 2005 6.6

I put a scriptmanager and updatepanel in my web gis application base on MapXtreme 2005 6.6; everytime I click the contols in the updatepanel the web browser will refresh the whole web page which is odd for Asp.Net Ajax 1.0.

Then I put the same scriptmanager and updatepanel and my own controls into another web page without MapXtreme 2005 6.6, it goes exactly the way I want. But I wonder Asp.Net Ajax 1.0 FrameWork should work right in every asp.net web page with any web controls outside the updatepanels

Have you create AJAX Enabled Web Site...

Check the property of ScriptManager EnablePartialRendering="true" and for UpdatePanel UpdateMode="Conditional"

Wednesday, March 21, 2012

asp controls unknown inside updatepanel in nested master

I have a master page with scriptmanager and update panel outside the contentplaceholder. Immediately the updatepanel and all nested master and non-master pages show all asp elements as unknown. If I move the update panel to inside the nested master content element it is still unknown as is all of the nested elements and pages.

I am running the december releases. I have un-installed and re-installed a couple of times. This is always the behavior. The code runs, but there is not intellisense and virtually everything is marked with the red underlines, and the error page is full (but doesn't stop the app coming up).

I looked at a number of posts suggesting rebuilding the toolbox. Nothing seems to help. However, the ajax toolkit controls are recognized because there is an @dotnet.itags.org.Register in the nested master.

Additionally, despite the post I found saying it had been fixed, I must keep my master pages open or none of the controls on any of the lower pages are recognized.

Anyone know of a post I missed about this issue?

/bump

I have the same issue.

In visual studio i create a new Ajax enabled website. I create a master page and a content page. The content page is to contain an update panel with some stuff in it. The AjaxControlToolkit is recognized while the Update Panel is not.

Cheers,

Michael


I'm also having this same problem. I have a Master page and my update panel is in the content page. AjaxControlToolkit controls are recognized but any controls within the update panel are not.
I'm also having this same problem. I have a Master page and my update panel is in the content page. AjaxControlToolkit controls are recognized but any controls within the update panel are not.

bump

I have 2 update panels (master/detail) that I am wiring together.

I am trying to make an object data source in UP2 use a praramater from a gridview in UP1. On creation of the data source, the Master gridview is not visible, but I hard coded it, and it actually works fine.

I think this is a bug in the UI of VS 2005.


Make sure you have the content inside your update panel wrapped with <ContentTemplate></ContentTemplate>