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

how can we write javascript for sharepoint2010 confirmation ModalDialog popup with Yes NO buttons?

Thank you.

I wrote like this.. but which is not working.. please anybody help.

function OpenConfigurationDialog(ConfirmationMessage) 
{
  var cloneModalContent = document.createElement('div');
  $("#lblConfirmationMessage").html(ConfirmationMessage);
  cloneModalContent.innerHTML = document.getElementById('ConfirmBox').innerHTML;

   var options = {
   html: cloneModalContent, // ID of the HTML tag or HTML content to be displayed in modal dialog
    width: 375,
   height: 150,
   title: "Please Confirm",
   dialogReturnValueCallback: CloseDialog, // custom callback function
   allowMaximize: false,
   showClose: true
};

SP.UI.ModalDialog.showModalDialog(options);
}


function CloseDialog(dialogResult, returnValue)
{

  if (returnValue == 'Yes') 
   {
    document.getElementById("btnSubmit").click();
    alert('Hi 1');
    return true;
   }

  if (returnValue == 'No')
  {
   alert('Hi 2');
    return false;

  }
}
**And placed div tags in PlaceholderMain in sp Designer 2010 aspx page.**

    <div id="ConfirmBox" style="display:none;">
    <div id="messageDiv" style="height:100px; padding-top:10px;padding-left:10px;padding-right:10px; font-weight:bold;">
    <label id="lblConfirmationMessage"> </label>
    </div>

    <div id="buttonDiv" style="float:right;padding-right:5px;">
    <input type="button" style="width:75px;" value="Yes" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Yes, 'Yes'); return false;" />
    <input type="button" style="width:75px;" value="No" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'No'); return false;"/>
    <asp:HiddenField runat="server" ID="hdnButtonClicked" value=""/>
    </div>
    </div>
share|improve this question
    
hello Robert.. can you give any solution for this ? –  praveen.ji Mar 14 at 11:52

4 Answers 4

SharePoint 2010 provides the Modal Popup that can be customized to implement the Confirmation box. Please check this article: Creating Custom Confirmation/Information Box in SharePoint 2010.

Hope it will guide you to solution..

In your code in the question you have not closed the function CloseDialog(dialogResult, returnValue) tag properly. } is missing at the end.

Have you tried to debug the js using IE-->F12 ? Are you getting any error? Does the control go into the JS code? Where does it stop?

share|improve this answer
    
Already Ashish did give that link Nachiket.. the thing is i'm unable execute the above script... Thanks –  praveen.ji Mar 14 at 12:10
    
Did you try to debug using IE->F12 ? Are you getting any error? Does the control go into the JS code? –  variable Mar 14 at 12:11
    
yes Nachiket.. it is not showing any error . couldnt get output. –  praveen.ji Mar 14 at 12:21
    
OK, answer the foll. questions:- 1. Do you know how to use debugger to debug the js? 2. Where does the debugger reach? 3. Are you using VS or Designer to deploy? –  variable Mar 14 at 12:26
    
Nachiket.. Is it correct way to place div tags content in PlaceHolderMain in aspx page in sp designer. Any alternative way to place that div tags? –  praveen.ji Mar 14 at 12:27

If it just a popup to confirm something, just use javascripts inbuild confirm(); function.

Example:

<script type="text/javascript">
if(confirm("Are you sure you are human?")) {
    alert("He is a human!");
}
</script>
share|improve this answer
    
No daniel it shows Ok Cancel buttons... need Yes No buttons. Thanks. –  praveen.ji Mar 13 at 12:43

Here's a tutorial on how to do it using jQuery and the native Dialog framework.

http://sharepointbrandon.com/2012/08/confirmation-modal-dialog-using-sharepoint-2010-modaldialog-vs-jquery-ui-modal-dialog/

The code is also featured on the Technet gallery: http://gallery.technet.microsoft.com/office/SharePoint-2010-Confirmatio-06a8ebc5

share|improve this answer

Try this

    <div id="ConfirmPopup" style="display:none;">
    <div id="messageDiv" style="height:100px; padding-top:10px;padding-left:10px;padding-right:10px; font-weight:bold;">
    <label id="lblConfirmationMessage"> /label>
    </div>

    <div id="buttonDiv" style="float:right;padding-right:5px;">
    <input type="button" style="width:75px;" value="Yes" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Yes, 'Yes'); return false;" />
    <input type="button" style="width:75px;" value="No" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 'No'); return false;"/>
    <asp:HiddenField runat="server" ID="hdnButtonClicked" value=""/>
    </div>
    </div>

Source:Click Here

share|improve this answer
    
You surely do not need jQuery for this.. –  Robert Lindgren Mar 13 at 12:42
    
Ya Robert.. Im also not looking for jquery.. Do you have any solution? –  praveen.ji Mar 13 at 12:44
    
Is it possible with SP.UI.ModalDialog.showModalDialog() ? –  praveen.ji Mar 13 at 12:48
    
Robert Your solution for this? –  Ashish Mar 13 at 14:56
    
@pravin ..see my updated answer –  Ashish Mar 13 at 15:10

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.