Monday, March 26, 2012

updatepanel , registerstartupscript gives me "Only one instance of a ScriptManager can be

i have a formview with a updatepanel nested in it. Also i m not using any masterpages so i have only one scriptmanager on the page. The page works fine without UpdatePanel/ScriptManager but if i have the UpdatePanel/ScriptManager on the page and i try to update the formview i get this error. here is similar code:

formview_itemupdated()

{

page.registerstartupscript(............);
formview1.databind(); //error occurs here
}

I also have some client javascript on in the <head> tags. Anyone know why is there an error? thanks

You now have to use the ScriptManager to register scripts from within an UpdatePanel, see:http://asp.net/AJAX/Documentation/Live/mref/O_T_System_Web_UI_ScriptManager_RegisterStartupScript.aspx

In short, the reason is because during a partial postback the ajax framework is looking for data that comes from the server to be in a special format.


I think i dint make myself clear in explaining the issue. the formview_itemupdated() is triggered by a button outside the UpdatePanel so i want a full postback. changing the Page.RegisterStartupScript to ScriptManager.RegisterStartupScript doesnt help either. I still get the same error. here is the hierarchy of my controls

<form view>
<templatefield>
<updatepanel/>
</templatefield>
<templatefield>
<mybutton that causes full postback by calling formview_itemupdated() />
</templatefield>
</formview>


i had scriptmanager nested in formview, i took it out of it and problem solved.


Ok, good. Sorry about the misunderstanding. For future reference: place the script manager at the top of the page and if possible, in the master page.


thanks David, also i will check out ur book =)

No comments:

Post a Comment