Home »

CSS Lost, Missing, Absent, Gone after Postback in Asp.NET

20. December 2008 by admin 1 Comments

I have a generic function in one of my helper libraries that allows me to open a new browser window when a button is selected.  The button posts back to the server runs some code and opens a new window.  I often use this sort of thing on a reporting page allowing me to post some search criteria and open a new window (a pdf report).

I found this type of helper function useful however I found that I was losing my CSS after the postback.

To avoid losing the css keep the following in mind:

  • ensure that your css files are include declaratively in your aspx page (not through code behind)
  • use Page.ClientScript.RegisterStartupScript(this.GetType(),”name”,script); (Not Response.Write)

The end helper function looks something like the following:

    /// <summary>

    /// redirect to a new page from codebehind

    /// </summary>   

    static public void RedirectToNewWindow(string url, System.Web.UI.Page page) {       

        string script = "<script>window.open('" + url + "');</script>";

        page.ClientScript.RegisterStartupScript(page.GetType(), "redirectscript",script);       

    }



Comments (1) -

United States SimpleScripts said:

Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your site is great, as well as the content!. Thanks For Your article about Performance Studies Methods: The Body of Evidence .

Add comment



  Country flag
biuquote
  • Comment
  • Preview
Loading