سؤال

I'm trying to open an informational error dialog when an error occurs during Page_Load.
I've defined the dialog and the functions necessary to initialize an open it, like this:

$(document).ready(function () {
    $('#errorDialog').dialog({
        autoOpen: false,
        height: 120,
        width: 500,
        draggable: false,
        resizable: false,
        modal: true,
        title: "Error!",
        open: function (type, data) {
            $(this).parent().appendTo("form");
        }
    });
});

function showErrorPopup() {
    $('#addNoteButton').hide();
    $('#errorDialog').dialog("open");
}

<div id="errorDialog">
    <asp:Label ID="errMessage" runat="server"></asp:Label>
    <input type="button" id="Button3" onclick="closeDialog('errorDialog');"
                class="inputASPButton" value="Zrušit" />
</div>

And I open it from Page_Load like this:

Page.ClientScript.RegisterStartupScript(typeof(Page), UniqueID, "showErrorPopup();", true);

It calls the function, as $('#addNoteButton').hide(); gets executed, hiding the button, but the dialog itself never shows up.

Any help is greatly appreciated.

هل كانت مفيدة؟

المحلول

As I can't see which script libraries you are including, the only suggestion I can make is to ensure you have jQuery UI included (http://jqueryui.com/download/), as the Dialog Widget is a part of this library as opposed to the standard jQuery library. I'm purely basing this on the fact that you are able to hide the button as intended, but unable open the dialog.

http://api.jqueryui.com/dialog/

نصائح أخرى

If your error messages are not dynamic you can use this code

Page.RegisterStartupScript("err_msg", "alert('Start Date not found!');");

I had to wrap my function call like this $(function(){ showErrorPopup(); }); before a jquery-ui dialog would display from RegisterStartupScript.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top