WebResource.axd not rendered in HTML
I'm having problems using the updateprogress control in ASP.NET. I've successfully created a small project using this control successfully, but when I created a simple .aspx page in my solution using the same code then it doesn't work. There is a mismatch in the rendered HTML code, where it doesn't work it is missing sections, e.g.
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTQ0OTI0ODUwMg9kFgICAw9kFgICBQ9kFgJmD2QWAgIDDw8WAh4EVGV4dAVqMTc6Mjc6MzA8YnIgLz4xNzoyNzozMDxiciAvPjE3OjI3OjMwPGJyIC8+MTc6Mjc6MzA8YnIgLz4xNzoyNzozMDxiciAvPjE3OjI3OjMwPGJyIC8+MTc6Mjc6MzA8YnIgLz4xNzoyNzozMGRkZIkvHCekERlfS9y4PA2asxGaEowE" />
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
开发者_如何学编程theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/WebResource.axd?d=xwJ8mgqm3wQN2acMjQykvA2&t=633941258702151333" type="text/javascript"></script>
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1'], [], [], 90);
Has anyone had this problem ? Maybe I am missing a javascript reference ?
Here is the html setting for the page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="UpdateProgressTest._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Update Progress</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
Some page content<br/>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" DynamicLayout="true" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate> Processing… </ProgressTemplate>
</asp:UpdateProgress>
More page content<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate> <div style="border-style:solid;background-color:gray;">
<asp:Button ID="Button1" runat="server" Text="Update"/><br/><br/>
<asp:Label runat="server" ID="time1"></asp:Label><br/></div><br/>
</ContentTemplate>
</asp:UpdatePanel><br/>
</div>
</form>
</body>
</html>
Here is the C# code behind section for the same page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace UpdateProgressTest
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(4000);
// base.OnLoad(e);
string theTime = DateTime.Now.ToLongTimeString();
for (int i = 0; i < 3; i++)
{
theTime += "<br />" + theTime;
}
time1.Text = theTime;
}
}
}
As I said, this code works fine in my test project, but fails when I use it in my solution (I created a new page, just to be sure my other controls were not interfering with the callback ajax mechanism)
Can anyone help ?
I always find it beneficial to explicitly specify the behaviors of MS AJAX controls. Start by setting the DisplayAfter property to something small (like 1) on the UpdateProgress control. Also, set the ChildrenAsTriggers to "true" for UpdatePanel1 to make sure it's doing an AJAX call when you click Button1.
Sometimes when I don't specify these things, the AJAX controls don't behave like I expect them to.
What do you see if you request the WebResource.asxd (with the querystring parameters) file directly (or if you're using FireBug switch to the Scripts tab then view the contents of the script)?
It's possible that your new projct doesn't have the correct settings in the web.config to serve this resource properly - compare both projects web.config files, especially the <httpHandlers>
section - you should have something like:
<add path="WebResource.axd" verb="GET"
type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
I was just figuring this out :D.
The problem was in the web.config file as Zhaph - Ben Duguid suggested. This was an old solution so I had upgraded it from .net 1.1, therefore it had the
<xhtmlConformance mode="Legacy"/>
under the node in web.config.
I changed that to
<xhtmlConformance mode="Transitional"/>
and things started working :D More info on how to configure Xhtml rendering in the asp.net web sites can be found here
精彩评论