Firefox Rendering Issue when JS Alerts Trigger

Last post 07-24-2007 12:14 PM by EndangeredMassa. 1 replies.

Sort Posts:

  • Firefox Rendering Issue when JS Alerts Trigger

    07-24-2007, 11:55 AM

    Environment
    Firefox 2.0.0.5
    Visual Studio 2005 (8.0.50727.42)
    .NET Framework 2.0.50727

    Issue
    When I encounter a page in my project that programatically adds a JavaScript Alert to the page during a postback, the background color appears to not be set properly when the page renders after the user closes the alert dialog box.

    Example Project
    Default.aspx

    <%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>Firefox Rendering Issue Test</title>
    </head>
    <body bgcolor="olive">
    <form id="form1" runat="server">
    <div style="background-color:Tan;">
    <br />
    <asp:Button ID="myButton" runat="server" Text="Do Something!" />
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    </div>
    </form>
    </body>
    </html>

     


    Default.aspx.vb

    Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub myButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles myButton.Click
    Response.Output.Write("<script language=""JavaScript"">alert('Here is the alert that will ruin my day.')</script>") End Sub
    End Class

     
    Screenshots
    Before

    After


     

    Solution
    The background can be fixed by making the window redraw itself. This can be done by doing a quick Alt+Tab to another window, then back again. But, this should never happen in the first place.

    Considerations
    If this topic has been discussed elsewhere, please point me in the right direction. The issue is very hard to search for given its very generic terms: "Firefox" "Render" "Postback" "Alert". I just can't find anything useful via Google or Forum searches.

    If this is strictly a Firefox issue, please let me know. I'll move on to a Firefox community for suggestions.

    Your Suggestions
    I would prefer to fix this issue by doing something other than changing the way that I am displaying the error message. There are many alerts that are added to the page in a similar fashion throughout the project. But, I'm not sure that there is another way to deal with this issue.

    All thoughts and suggestions are appreciated. 

  • Re: Firefox Rendering Issue when JS Alerts Trigger

    07-24-2007, 12:14 PM
    Answer

    I figured out what the real issue is, here. The JavaScript is added to the top of the page, outside of the HTML tag. It's just breaking when Firefox tries to render it.

    So, I'm going to have to add a Literal control inside the Body tag for any scripts that I may want to insert into the page. Then, I can just change the line that adds the script to something like this:
    myScriptLiteral.Text = "<script language=""JavaScript"">alert('Here is the alert that will ruin my day.')</script>"

    That solves the issue.
     

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter