views:

109

answers:

2

I feel like this is a stupid questions, but I am finding it hard to get this answered.

I only want to show the jquery dialog when the page first renders. After the page renders there are multiple operations that cause the page to postback, but the user doesn't navigate away from that page.

How do I disallow the jquery dialog from showing on those postback events.

Thanks in advance!

A: 
  • You could store a variable on the server to denote if it's a first visit.
  • You could place something in a query-string (or even a cookie I suppose) and have some javascript check for it to determine if it should display it.
    (http://www.yoursite.com/yourpage?firstvisit=false)
Justin
+1  A: 

One approach could be to remove the dialog element on postback, that way the jquery selector doesn't match anything. Not sure if it is the best way or not, but it should work.

void Page_Load()
{
    // stuff
    if(this.IsPostback)
        dialogElement.Visible = false;
}

Your dialogElement could be anything, as long as there is a runat="server" you can access it from the code-behind. The Visible property controls whether or not the element is rendered in the HTML output so if it is false, then the element will not exist in the DOM.

ckramer
Thanks for your responses. Since the dialog needs to show up when the page is loaded and can also be reopened by clicking a link I came up with a solution similar to ckramer's. HtmlGenericControl bdy = (HtmlGenericControl)Master.FindControl("MasterBody");if (!IsPostBack) { bdy.Attributes.Add("onload", "isPostBack()"); } else { bdy.Attributes.Remove("onload"); }the javascript function isPostBack() { $('#thedialog').dialog('open'); return false; }
mellowyellow77