At the end of a call back in my SharePoint application that I handled in c# I would like to put up a modal dialog box displaying the result and offering a choice to the user to continue or return to the site. The only way I found in which modal dialogboxes can be put on screen is done in JavaScript via SP.UI.ModalDialog.showModalDialog.
I added my JavaScript function to the top of my page and if I call ShowDialog(); from a normal URL or onClick event of a HTML button, it all works fine so I believe the JavaScript to be correct:
<script type="text/javascript">
function ShowDialog() {
var options = { url: "DialogPage.aspx?IsDlg=1", width: 400, height: 300 };
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}</script>But if I add the following to the end of the C# code handing the Click event of an <asp:Button>, it never shows.
ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "ShowDialog();", true);
However, if I replace the call to my JavaScript function with an JavaScript 'alert', the alert pops up so it looks like I can call JavaScript at this moment.
ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "alert('this shows');", true);Assuming that the ShowDialog function might not been loaded, I tried to include the whole script in the script block but that didn't help either:
ScriptManager.RegisterClientScriptBlock(Page, GetType(), Guid.NewGuid().ToString(), "<script type='text/javascript'>function ShowDialog() {var options = { url: 'DialogPage.aspx?IsDlg=1', width: 400, height: 300 }; SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);} ShowDialog();</script>", true);No Exceptions are thrown.
Could you give me a suggestion why my JavaScript function isn't called?
Is there a better way to put up a modal dialogbox in a SharePoint application from pure C# that I missed?
How would you put up a modal dialogbox in the case I described if I cannot do this via JavaScript?
Thanks for you help.