Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

2 Answers 2

A simple example:

<a title="aTitle" onmouseover="javascript:this.style.cursor='hand'; 
    onclick="javascript:SP.UI.ModalDialog.ShowPopupDialog('http://path/to/NewForm.aspx';);
    return false;">
    link Text
</a>

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

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 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 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
add comment
up vote 3 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);
          SP.UI.ModalDialog.showModalDialog(options);

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

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

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"))
    {
        //BindGridDATA();
        BindGrid();
    }
}
share|improve this answer
add comment

Your Answer

 
discard

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.