Conditional Query String Panel – CSS which is only used in a dialog

This is something I initially knocked up so that I could add CSS to a page conditional on the query string present. I basically wanted to change the CSS if the page was showing a dialog.

It is a very simple control which extends the ASP.Net “Panel” class (which basically outputs a DIV). I added some Pre-Render logic to check for a query string value and only show the contents if that Query String is present.

public class ConditionalQueryStringPanel : Panel
{     public String QueryString
   { get; set; }

   protected override void OnPreRender(EventArgs e)
   {       base.OnPreRender(e);
       this.Visible = Page.ClientQueryString.Contains(QueryString);


In the example usage below I am using this panel to conditionally change the margin of one of my containers when the page is showing in a pop-up dialog

<MJH:ConditionalQueryStringPanel runat=”server” QueryString=”IsDlg=1″>
    <style type=”text/css”>
         margin-left: 0px;
      }    </style>

Something quite simple but hopefully you should be able to make use of it.