【问题标题】:ASP.NET UpdatePanel not working with FirefoxASP.NET UpdatePanel 不适用于 Firefox
【发布时间】:2009-12-09 20:24:43
【问题描述】:

我正在尝试使用 ASP.NET 3.5 做一些听起来相当简单的事情。用户应该能够将“社区”添加到数据库中,并在选中一个框后,从下拉菜单中选择一个父社区,该菜单仅在选中该复选框时显示。为此,我在 UpdatePanel 中使用了一个面板(最初设置为 Visible=false)。我的问题是,虽然它在 IE8 和 Chrome 中工作(尽管 Chrome 重新加载整个页面而不仅仅是 div),但在 Firefox 中没有任何反应。 根本没有发送任何查询。我应该提一下,下面的所有代码都在一个用户控制页面中,而不仅仅是一个 Web 表单。

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CommunityEditing.ascx.cs"     Inherits="Folke.Code.Element.CommunityEditing" %>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div class="content">
<asp:Label id="editingFeedback" runat="server" />
<dl>
<dt><%=Folke.Code.Texte.L("Name") %></dt><dd><asp:TextBox ID="name" runat="server" /><br />
<asp:RequiredFieldValidator ID="nameReq" runat="server" ControlToValidate="name" ErrorMessage="Community name is required!" /><br />
</dd>
</dl>
<asp:CheckBox ID="cbToggle" runat="server" 
    OnCheckedChanged="TogglePanel" 
        Text="Has a parent community" AutoPostBack="True" />
<asp:UpdatePanel ID="parentCommunityUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
    <asp:Panel id="parentCommunityPanel" runat="server" Visible="false">
        <asp:DropDownList ID="communityListDropDownList" runat="server"/>
    </asp:Panel>
</ContentTemplate>
<Triggers>
    <asp:PostBackTrigger ControlID="cbToggle" />
</Triggers>
</asp:UpdatePanel>
<asp:Button runat="server" Text="Add" ID="send" onclick="send_Click" />
</div>

代码隐藏代码非常简单:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Populate drop down menu
            var session = HibernateModule.CurrentSession;
            var communityList = from community in session.Linq<Community>()
                                select community;
            communityListDropDownList.DataValueField = "id";
            communityListDropDownList.DataTextField = "name";
            communityListDropDownList.DataSource = communityList;
            communityListDropDownList.DataBind();
        }
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
    }

protected void TogglePanel(object sender, EventArgs e)
    {
        if (cbToggle.Checked)
        {
            parentCommunityPanel.Visible = true;
        }
        else
        {
            parentCommunityPanel.Visible = false;
        }
    }

由于这在 IE8 中运行良好,我尝试将非常相似的代码(几乎相同)放在 Web 窗体中,它在 Firefox 中运行良好。由于上面的代码嵌入在 MasterPage 中,然后是 Web 表单,然后是用户控件,所有这些“堆叠”会导致问题吗?我在这上面花了几个小时,但我找不到任何有意义的线索或解释。

编辑:

在检查 Firefox 的错误控制台时,浏览器会报告:

错误:表单未定义 源文件:http://localhost:54003/EditCommunity.aspx 线路:25

第 25 行是该脚本的第一个 if 语句:

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
    theForm.__EVENTTARGET.value = eventTarget;
    theForm.__EVENTARGUMENT.value = eventArgument;
    theForm.submit();
}
}
//]]>
</script>

【问题讨论】:

  • 页面上是否有任何 javascript 错误?
  • 你是对的,确实如此。我编辑了问题以添加错误详细信息。
  • 抱歉不能给你一个正确的答案,但是在页面上查看源代码并检查你是否有类似
    的东西。如果 document.forms['aspnetForm'] 返回“未定义”,则标记中可能有问题。
  • 表单在那里,但未被 Firefox 解释。 Firebug 帮助我得出了这个结论,因为
    标签没有显示在它的控制台中。将
    标签嵌套到 中解决了这个问题。

标签: asp.net-ajax user-controls


【解决方案1】:

我发现了问题。在我的 MasterPage 中,标签被放置在该部分内。表单标签必须在页面的部分中。

【讨论】:

    【解决方案2】:

    是的,你的高斯看起来是正确的...... 看起来是多个脚本管理器导致问题,尝试将脚本管理器放在页面上而不是用户控件上

    【讨论】:

    • 将脚本管理器放在 MasterPage 中并不能解决 Firefox 中的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多