I have a button which redirect to newform.aspx . I want the newform.aspx to be opened in a dialog box . currently i cannot see this thing opening in a popup , hw to achieve this ?

3 Answers 3


A simple example:

<a title="aTitle" onmouseover="javascript:this.style.cursor='hand'; 
    return false;">
    link Text

You can read more about SP.UI.ModalDialog at http://msdn.microsoft.com/en-us/library/ff408909.aspx

  • Can i add Source ID to the url and send ? like onclick="javascript:SP.UI.ModalDialog.ShowPopupDialog('path/to/NewForm.aspx ?sourceid+"string"=';);
    – Nikhil J
    Commented Sep 29, 2011 at 16:23
  • You're just passing a URL to the ShowPopupDialog function, so you can add any values to it that you want to.
    – webdes03
    Commented Sep 29, 2011 at 16:40
  • wehn i click button on newform.aspx , i need it to come back to my home page
    – Nikhil J
    Commented Sep 30, 2011 at 4:59
  • By "come back to my home page" do you mean closing the modal window, or physically redirecting the parent window? You'd probably need to do a little more work on the JavaScript to accomplish that. Passing "?source=/path/to/page.aspx" will most likely redirect to the page within the modal window.
    – webdes03
    Commented Sep 30, 2011 at 12:23
  • Also, I just noticed in your comment that you're using ?sourceid... it needs to be "source", so the example would be: "path/to/NewForm.aspx?source="+string
    – webdes03
    Commented Sep 30, 2011 at 12:24

Found the solution ,

Visual Wp :

Add below javascript

<script type="text/javascript">

      function AddWebParts(addedwebparts) {

          var varUrl = "<%=varPageUrl%>";
          var options = SP.UI.$create_DialogOptions();
          options.url = varUrl + addedwebparts;
          options.allowMaximize = true;
          options.showClose = true;
          options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);

          function CloseCallback(dialogResult) {
              if (dialogResult == SP.UI.DialogResult.OK) {

                 __doPostBack('AddWebpartsToPage'); // this will post back the page with the argument specified

Page load :

varPageUrl = SPContext.Current.Site.Url.ToString();
appendurl = "/Lists/QuickLinks/NewForm.aspx" + "?Source=" + Page.Request.Url.ToString();
btnQuickLinks.Attributes.Add("onclick", "javascript:AddWebParts('" + appendurl + "');return false;");

after button click your changes should be updated so write below code in page load

string eventArgument = this.Page.Request.Params.Get("__EVENTTARGET");
if (eventArgument != null)
    if (eventArgument.Contains("AddWebpartsToPage"))

Just go to list settings then go to advance settings, under general settings click on advance settings, and then at the bottom of the page click yes for "Launch forms in a dialog?". All your forms will get open in a modal dialog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.