【问题标题】:Ajax.net update panels not working on mozilla firefoxAjax.net 更新面板在 mozilla firefox 上不起作用
【发布时间】:2010-01-27 16:31:46
【问题描述】:

不知道为什么,但是在为控件进行回发以更新 ajax updatePanel 时,它实际上完成了页面的完整回发,它在 IE 上运行良好,但在 mozilla 上它会重新加载整个页面。

<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:Panel ID="userLogin" Visible=false runat=server>
    <table>
        <tr>
            <td colspan="2">
                <asp:Label ID="Label27" runat="server" style="font-weight: 700" 
                    Text="Registered Users"></asp:Label>
            </td>
            <td class="style2">
                &nbsp;</td>
            <td>
                <asp:Label ID="Label30" runat="server" Text="New Users" 
                    style="font-weight: 700"></asp:Label>
            </td>
            <td class="style7">
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="Label28" runat="server" Text="Email"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="TextBox11" runat="server" Width="160px" TabIndex="1"></asp:TextBox>
            </td>
            <td class="style2">
                &nbsp;</td>
            <td>
                <asp:Label ID="Label31" runat="server" Text="Email"></asp:Label>
            </td>
            <td class="style7">
                &nbsp;<asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        <asp:TextBox ID="TextBox13" runat="server" AutoPostBack="True" 
                            ontextchanged="TextBox_TextChanged" TabIndex="3" Width="160px"></asp:TextBox>
                        <asp:Image ID="Image6" runat="server" ImageUrl="~/Classifieds/images/notOk.jpg" 
                            Visible="False" />
                        <asp:Image ID="Image5" runat="server" ImageUrl="~/Classifieds/images/ok.jpg" 
                            Visible="False" />
                    </ContentTemplate>
                </asp:UpdatePanel>

         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Label ID="registerErrorLabel" runat="server" ForeColor="Red"></asp:Label>
                        &nbsp;<asp:UpdateProgress ID="UpdateProgress1" runat="server">
                            <ProgressTemplate>
                                <asp:Image ID="Image4" runat="server" 
                                    ImageUrl="~/Classifieds/images/ajax-loader.gif" />
                            </ProgressTemplate>
                        </asp:UpdateProgress>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="TextBox13" EventName="TextChanged" />
                        <asp:AsyncPostBackTrigger ControlID="TextBox15" EventName="TextChanged" />
                        <asp:AsyncPostBackTrigger ControlID="CheckBox4" EventName="CheckedChanged" />
                    </Triggers>
                </asp:UpdatePanel>

文本框自动回发为真,它只是检查用户是否存在或有效,并在更新面板内的一个标签上显示一条消息。

这是文本框触发的事件背后的代码:

protected void TextBox_TextChanged(object sender, EventArgs e)
{
    if (isEmail(TextBox13.Text))
    {
        if (DB2.alreadyRegistered(TextBox13.Text))
        {
            registerErrorLabel.Text = "This email has already been registered,<br/>If you forgot your password please <a href='../../../forgot.aspx' target=blank>click here</a> (will open on a new window)";
            registerErrorLabel.Visible = true;
            Image5.Visible = false;
            Image6.Visible = true;
            TextBox13.BorderColor = System.Drawing.Color.Red;
        }
        else
        {
            registerErrorLabel.Visible = true;
            Image5.Visible = true;
            Image6.Visible = false;
            TextBox13.BorderColor = System.Drawing.Color.Green;
        }     
    }
    else {
        registerErrorLabel.Text = "Please use a valid email";
        Image5.Visible = false;
        Image6.Visible = true;
        TextBox13.BorderColor = System.Drawing.Color.Red;
    }        
}

【问题讨论】:

  • 嗯,您的更新面板中没有标签?您是否显示其中一张图片来显示它是否有效?
  • 也只是一个建议,但您应该真正拥有有意义的控件 ID,因为这会在后面的代码中变得混乱,并通过使用错误的控件导致一些奇怪的行为。这可能是现在正在发生的事情,但是如果没有看到您的代码就很难判断。
  • 抱歉,这里有两列,一列是注册用户,另一列是新用户(一张表有两列)忘记包含第二个更新面板,一列在顶部有图片在文本框旁边,另一个在 registerErrorLabel 所在的底部(如果有则显示错误的标签)
  • 您使用的是什么版本的 C# ASP.NET?你最近升级到这个版本了吗?

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


【解决方案1】:

它可能在 IE 中无法真正工作。

您需要在 ScriptManager 上设置 EnablePartialRendering 参数。

【讨论】:

  • 它设置为 true,是默认设置,但也会尝试在代码中将其设置为 true...希望就是这样...
【解决方案2】:

尝试将 UpdatePanel 的 UpdateMode 设置为 Conditional。

我看到的和你一样 - Chrome 和 Firefox 上的回发,但 IE 上没有(所有最新版本)。可能是 IE 在没有指定更新模式的情况下运行良好,您可能必须在其他浏览器中更加明确。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-20
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多