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

posted on Saturday, December 20, 2008 9:40 AM

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


No comments posted yet.
Post Comment
Title *
Name *
Email
Url
Comment *
Please add 2 and 2 and type the answer here:

About Me

An engineer by training and a software developer at heart. My techniques and approaches meld engineering approaches with software technology.

Core to these principles is a systematic approach to the development of software with a strong lifecycle and process management emphasis through adoption of mature technologies.

Ten years designing heavy structural steel and concrete structures and 12 years in the software development profession have embedded strong project management and business knowledge in my approaches.

Subscribe to Rss Feed


Follow me on twitter @dyardy