title: How to stop a modal dialog popup from showing in sharepoint code behind
body: <p>I have created a Modal Dialog Popup in jQuery/javascript in a Visual Web Part which shows every time the page loads. There is a submit button in the popup and when it is clicked, I store the username and the date at which it was acknowledged in a custom list. jQ code which works:
  <br/></p>
  
  <pre><code> &lt;script language="javascript" type="text/javascript"  src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;
  
  &lt;/script&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
      $(document).ready(function () {
          ExecuteOrDelayUntilScriptLoaded(openDialog, "SP.js");        
      });
  
      //open dialog
  
  
  
      // Call openDialog method on button click or on page load  
  
      function openDialog() {
          //alert("In funciton opendialog");
          var options = {
  
              //html: divModalDialogContent,  // ID of the HTML tag
  
              // or HTML content to be displayed in modal dialog
  
              width: 400,
  
              url: "/_layouts/ModalDialog1/ModalDialog.aspx",
  
              height: 125,
  
              title: "Acknowedgement Popup",
  
              dialogReturnValueCallback: dialogCallbackMethod,  // custom callback function
  
              allowMaximize: false,
  
              showClose: false
  
          };
          SP.UI.ModalDialog.showModalDialog(options);
  
      }
  
  
      // Custom callback function after the dialog is closed
  
      function dialogCallbackMethod(result, returnValue) {
  
          alert("dialogResult" + result + "nreturnValue" + returnValue);
                  if(result == SP.UI.DialogResult.OK)
           {
           alert("You chose the OK button");
           //document.title = returnValue;
           }
  
          if(result == SP.UI.DialogResult.cancel)
           SP.UI.Notify.addNotification("You chose the Cancel button");
           }
  
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p><br/>
  Now, I'm adding the username in the list with this code. I'm storing it in the list using an aspx page which is triggered when the button is clicked in popup:</p>
  
  <p><br/></p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
      {
          Context.Response.Write(@"&lt;script type='text/javascript'&gt;
                                  alert('Thanks for acknowledging!');
                                  window.frameElement.commitPopup();
                                  &lt;/script&gt;");
          Context.Response.Flush();
          Context.Response.End(); 
  
          string username;
          using (SPSite site = new SPSite(SPContext.Current.Web.Url))
          {
              site.AllowUnsafeUpdates = true;
              using (SPWeb web = site.RootWeb)
              {
                  web.AllowUnsafeUpdates = true;
                  SPUser user = web.CurrentUser;
  
                  username = user.LoginName.ToString();
  
  
                  //adding list item
                  SPList l = web.Lists["Acknowledgements"];
                  SPListItem li = l.Items.Add();
                  li["User"] = username;
                  li["Acknowedgement Date"] = System.DateTime.Today;
                  li.Update(); 
  
              }
  
  
          }
  </code></pre>
  
  <p>Now the client requirement is to show the modal dialog popup at the start of the month and not show the modal dialog popup for that month if the username already exists in the custom list. I googled and came to know about registerstartupscript by which you can write javascript in code behind and used it but it isn't working. I'm planning on comparing the username from the list and the currently logged in username and not show the popup if he has already acknowledged but it beats me how I'd achieve that, moreover, with the javascript being in the client side. 
  <br/></p>
  
  <pre><code>string Script = @"function openDialog() { var options={
                      width:400,
                      url: '/_layouts/ModalDialog/ModalDialog.aspx', height:125,
                      title: 'Acknowedgement Popup',
                      dialogReturnValueCallback: dialogCallbackMethod, 
                      allowMaximize: false,
                      showClose: false
                      };
                      SP.UI.ModalDialog.showModalDialog(options);
                       }";Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "openDialog", Script, true); 
  </code></pre>
  
  <p><br/>
  Am I going the right way with all this? I'm kinda new to SharePoint so please help.
  This has me in a predicament. Thanks in advance for all your help.</p>