asp.net AJAX RC Tip: updateprogress Create error problems when there is no UpdatePanel in the page

Source: Internet
Author: User
Tags add net
Ajax|asp.net| Create | problem | page

Yesterday afternoon, Im encountered brother, was asked why the installation of ASP.net AJAX RC, some pages always create updateprogress when the script error. At that time gave a not too good solution, just a simple look at the relevant implementation of System.Web.Extensions.dll, came up with a better solution, here simply to say.

First, I simulate a "scene of the incident" and start to solve the problem: In general, it may be necessary to have a unified updating Animation on all pages, It is possible to put a updateprogress together with ScriptManager in MasterPage, as follows:

Site.master
<asp:scriptmanager id= "ScriptManager1" runat= "Server" scriptmode= "Debug" >
</asp:ScriptManager>

<asp:contentplaceholder id= "Main" runat= "Server" ></asp:ContentPlaceHolder>

<asp:updateprogress id= "UpdateProgress1" runat= "Server" >
<ProgressTemplate>
Hello world!
</ProgressTemplate>
</asp:UpdateProgress>

If you generate a page directly, and add a UpdatePanel at your discretion:

Default.aspx
<asp:content id= "Content1" contentplaceholderid= "Main" runat= "Server" >

<asp:updatepanel runat= "Server" >
<ContentTemplate>
...
</ContentTemplate>
</asp:UpdatePanel>

</asp:Content>

The HTML generated at this time is:

Html
...
<form>
...
<script src= "/ajaxenabledwebsite/webresource.axd?..."
Type= "Text/javascript" ></script>

<!--microsoftajax.js-->
<script src= "/ajaxenabledwebsite/scriptresource.axd?..."
Type= "Text/javascript" ></script>

    <!--microsoftajaxwebforms.js
    <script src= "/ Ajaxenabledwebsite/scriptresource.axd?... "
 type=" Text/javascript "></SCRIPT>

...
<script type= "Text/javascript" >
<!--
Sys.Application.initialize ();
Sys.Application.add_init (function () {
$create (
Sys.ui._updateprogress,
{"Associatedupdatepanelid": null,
"DisplayAfter": 500,
' Dynamiclayout ': true},
Null
Null
$get ("Ctl00_updateprogress1"));
});
-->
</script>
...
</form>
...

Note that at this point the updateprogress is created in a Sys.UI.Control form, and sys.ui._updateprogress (it appears asp.net Ajax does not want us to use this class directly) is introduced in the Microsoftajaxwebforms.js file.

So the problem arises, if the page is not UpdatePanel, then microsoftajaxwebforms.js file will not be introduced, and that sentence $create still! This causes JavaScript errors to occur. The method I offered at the time was: then force a UpdatePanel in the Site.master. As follows:

Forced UpdatePanel
<asp:updatepanel runat= "Server" updatemode= "Conditional" id= "UP1" >
<ContentTemplate></ContentTemplate>
</asp:UpdatePanel>

Here the UpdateMode is set to conditional, that is to say, the UpdatePanel here will never be updated, its role is only "forced" Microsoftajaxwebforms.js file is introduced. But that's not a good solution.

If you want to solve this problem, do not let the $create statements appear not to do it? After reviewing the code and discovering that the $create statement only appears if the ScriptManager enablepartialrendering property is true, then we expose the ScriptManager attribute. We can modify the code of the site class in Site.master.cs to add an attribute to it:

Site.master.cs
public bool EnablePartialRendering
{
Get
{
return this. scriptmanager1.enablepartialrendering;
}
Set
{
This. scriptmanager1.enablepartialrendering = value;
}
}

Then set the MasterPage EnablePartialRendering property to False on the page. It is to be noted that only the Init phase can set the ScriptManager enablepartialrendering property. As follows:

Default.aspx.cs
protected override void OnInit (EventArgs e)
{
Base. OnInit (e);

(This. Master as Site). EnablePartialRendering = false;
}

This concludes the task.

Http://www.cnblogs.com/JeffreyZhao/archive/2006/12/20/597416.html



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.