When you have used Asp:Button
, it is doing postback. Hence the opened dialog model is closed. You can avoid the postback event by adding "return false" after the method call in the OnClientClick
event. It worked fine for me.
<asp:Button ID="btnJustify" runat="server" Text="Justify" OnClientClick="Justify();return false" />
In order to update the details through modal, the item Id needs to be passed. Seems you are not passing the Id parameter in your code.
Below code snippet works for your scenario.
<script type="text/javascript">
function Justify() { var options = SP.UI.$create_DialogOptions(); options.width = 500; options.height = 500;
options.url = "/sites/SAMS/Lists/DownloadJustify/EditForm.aspx?ID=1"; options.dialogReturnValueCallback = Function.createDelegate(null, dialogReturnValueCallback); options.showClose = true; SP.UI.ModalDialog.showModalDialog(options); }
function dialogReturnValueCallback(res, retVal) {
if (res === SP.UI.DialogResult.OK) {
alert('success');
}
else {
alert('failed');
}
}
</script>
Hope this helps to resolve your issue.