0

I am unable to make below code right. I have read that we have to save the context to a variable but i cannot find a working example.

I have a button:

Button Code:

<asp:Button ID="Save_BTN" runat="server" Text="Save" OnClientClick="ShowDialog()" OnClick="Save_BTN_Click" Width="48px" />



function ShowDialog() {
$(".selector").dialog({
            modal: true,
            autoOpen: false,
            resizable: false,
            width: '450',
            position: 'top',
            dialogClass: 'no-close'
        });


 $('.selector').dialog('open');
 $('#wait').css('display', ''); 


}
 /////////////////////
  protected void Save_BTN_Click(object sender, EventArgs e)
  { 
    if(OK)
    {
       ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(string), "Script", "UpdateHelloWithNewKEY('" + BusinessUnit["gr_encryptionkey"].ToString() + "')", true);
    }
  }
//////////////////////
function Update(OldEncryptedHello) {
If(OK)
{   // Do Update work}
}
else
{
  alert("Invalid Old KEY.");
  $(".selector").dialog("close");  // Error on this line
  }

But I am getting the following error on the line:

Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'

6
  • You are calling the dialog('open') conditionally(iff OK is true). And there is a change that OK can be false and if OK is false, the dialog won't open and in the Update function dialog close is called which is invalid. Instead you should move the $(".selector").dialog("close"); to the If statement in Update method. Commented May 14, 2014 at 5:27
  • if(OK) is not true then Update function is not called. But the dialog is shown all the time but cannot be closed Commented May 14, 2014 at 5:30
  • 1
    As per your modified code you're opening dialog whenever you've clicked the button irrespective of ok. So call this script ScriptManager.RegisterStartupScript(this, GetType(), "closeModal", "$(".selector").dialog("close");", true); before checking the condition for OK in codebehind. Commented May 14, 2014 at 5:42
  • But I want to close the dialog from Update method only if some error occured or argument received is not valid. Commented May 14, 2014 at 5:45
  • The code looks ok this time. Did you run the code this time to check if the same issue persists ? Commented May 14, 2014 at 5:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.