【问题标题】:WebResource.axd not rendered in HTMLWebResource.axd 未在 HTML 中呈现
【发布时间】:2010-02-09 17:35:44
【问题描述】:

我在使用 ASP.NET 中的 updateprogress 控件时遇到问题。我已经成功地使用这个控件成功地创建了一个小项目,但是当我使用相同的代码在我的解决方案中创建一个简单的 .aspx 页面时,它就不起作用了。呈现的 HTML 代码不匹配,它不起作用,缺少部分,例如

<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&amp;t=633941258702151333" type="text/javascript"></script>

Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1'], [], [], 90);

有人遇到过这个问题吗?也许我缺少 javascript 参考?

这是页面的html设置

<%@ 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> 

这是同一页面的 C# 代码隐藏部分:

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; 
        }
    }
}

正如我所说,这段代码在我的测试项目中运行良好,但在我的解决方案中使用它时失败(我创建了一个新页面,只是为了确保我的其他控件不会干扰回调 ajax 机制)

谁能帮忙?

【问题讨论】:

    标签: c# asp.net javascript ajax asp.net-3.5


    【解决方案1】:

    我总是发现明确指定 MS AJAX 控件的行为是有益的。首先在 UpdateProgress 控件上将 DisplayAfter 属性设置为较小的值(如 1)。此外,将 UpdatePanel1 的 ChildrenAsTriggers 设置为“true”,以确保在您单击 Button1 时它正在执行 AJAX 调用。

    有时,当我不指定这些内容时,AJAX 控件的行为就不会像我期望的那样。

    【讨论】:

    • 为 updateprogress 控件设置 DisplayAfter="1",为 UpdatePanel 设置 ChildrenAsTriggers="true"。结果相同,如果我理解正确,那么如果有任何服务器控件正在使用它,则会添加 webResource 引用,但是两个页面的代码相同,所以这应该不是问题。我还查看了 web.config 进行比较,所涉及的部分是相同的:S
    【解决方案2】:

    如果您直接请求 WebResource.asxd(带有查询字符串参数)文件(或者如果您使用 FireBug 切换到“脚本”选项卡然后查看脚本的内容),您会看到什么?

    您的新项目可能在 web.config 中没有正确的设置来正确提供此资源 - 比较两个项目的 web.config 文件,尤其是 &lt;httpHandlers&gt; 部分 - 您应该有类似的内容:

    <add path="WebResource.axd" verb="GET"
         type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
    

    【讨论】:

    • 感谢您的回复,我刚刚想通了。你是对的,问题出在 web.config 但与 节点 中的设置有关
    • 没问题 - 我以前没有遇到过,很高兴了解它:)
    【解决方案3】:

    我只是想通了 :D。

    问题出在 web.config 文件中,正如 Zhaph - Ben Duguid 所建议的那样。这是一个旧的解决方案,所以我从 .net 1.1 升级了它,因此它有

    <xhtmlConformance mode="Legacy"/> 
    

    在 web.config 中的节点下。

    我改成

    <xhtmlConformance mode="Transitional"/> 
    

    一切都开始了 :D 更多关于如何在 asp.net 网站中配置 Xhtml 渲染的信息可以在here找到。

    【讨论】:

      猜你喜欢
      • 2015-08-06
      • 2014-03-14
      • 2017-09-04
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 2013-05-25
      • 2015-09-23
      • 2023-03-15
      相关资源
      最近更新 更多