Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9054289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:39:06+00:00 2026-06-16T13:39:06+00:00

I have created a Modal Dialog Popup in jQuery/javascript in a Visual Web Part

  • 0

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:

 <script language="javascript" type="text/javascript"  src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">

</script>
<script language="javascript" type="text/javascript">
    $(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");
         }

    }

</script>

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:

protected void Button1_Click(object sender, EventArgs e)
    {
        Context.Response.Write(@"<script type='text/javascript'>
                                alert('Thanks for acknowledging!');
                                window.frameElement.commitPopup();
                                </script>");
        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(); 

            }


        }

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.

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); 

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:39:10+00:00Added an answer on June 16, 2026 at 1:39 pm

    In your markup, you can add a Literal as a placeholder for a JS flag variable… make sure to add it before your openDialog function:

    <asp:Literal runat="server" ID="DlgFlag"></asp:Literal>
    

    In your codebehind, check against the list, and if the username is found, output a flag to the literal:

    if (isUsernameInListAlready)
    {
        DlgFlag.Text = "<script type=\"text/javascript\">var dlgFlag = true;</script>";
    }
    

    In your openDialog function, check for this flag at the top, and simply exit w/o opening the dialog if the flag is present:

    function openDialog() {
        if (dlgFlag) return;
    
        //alert("In funciton opendialog");
        var options = {
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created JQGrid with Jquery modal dialog for Delete. Jqgrid with inline editing
I created a Simply Modal popup dialog which works fine if you click on
I have a modal dialog that is created with the following: procedure TFormCompose.createParams(var Params:
I have created a dialog with the JQuery dialog plugin. My dialog is defined
I'm having some trouble with IE6 and jQuery UI. I have a popup dialog
I have created a CPropertySheet -based modal dialog in MFC (using BCGSoft classes derived
I have created a dialog popup on click to show - I would like
I've created an HtmlHelper that helps me show a jQuery modal dialog: I set
I have created a page which is autorefreshing via ajax requests. On this page
Modern browsers have multi-tab interface, but JavaScript function window.showModalDialog() creates a modal dialog that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.