SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?

share|improve this question

A simple example:

<a title="aTitle" onmouseover="'hand'; 
    return false;">
    link Text

You can read more about SP.UI.ModalDialog at

share|improve this answer
Can i add Source ID to the url and send ? like onclick="javascript:SP.UI.ModalDialog.ShowPopupDialog('path/to/NewForm.aspx ?sourceid+"string"=';); – Nikhil Jangle Sep 29 '11 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 Sep 29 '11 at 16:40
wehn i click button on newform.aspx , i need it to come back to my home page – Nikhil Jangle Sep 30 '11 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 Sep 30 '11 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 Sep 30 '11 at 12:24
up vote 4 down vote accepted

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"))
share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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