Andy
Andy

Reputation: 21

closing pop up window on button click(if successcede) and reload parent window

I am using this code.This pop up window pops up when I clicks a button on the main page.Now I want the pop up window to be closed if the password is successfully changed and reload the main page,but if the password is not changed then refresh the pop up window again. I used javascript for form validationenter code here Here is the code.....

<asp:Textbox id="curnt_paswrd" textmode="Password" runat="server" size="30" />
<asp:Textbox id="new_paswrd" textmode="Password" runat="server" size="30" />
<asp:button ID="btnChange" class="submit-button" 
          OnClientClick="return validate()" runat="server" Text="Change" 
          onclick="btnChange_Click" />

Upvotes: 0

Views: 9315

Answers (2)

Gauravsa
Gauravsa

Reputation: 6528

You can do simply like this: When you return true the main page automatically refreshes.

function validate() {
    var strOutput = window.showModalDialog('ChangePassword.aspx', null, "dialogWidth:750px; dialogHeight:190px; dialogHide:false; edge:raised; center:yes; help:no; scroll:no; status:no;resizable:no;");

    if (strOutput == undefined)
        return false;

    else if (strOutput == '') 
        return false;

    else return true;
}

On your popup page, in javascript:

function IsSavePasswordSuccess() 
{
    window.returnValue = '<%=hdnSaveClickStatus.Value%>';
    window.close();
}

The hidden field will be set as. It will be set in your C# method.

<asp:HiddenField runat="server" ID="hdnSaveClickStatus" />

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630569

When you reload the that popup you can do something like this in script if the change was successful:

window.opener.location.reload();
window.close();

So for example using RegisterStartupScript:

ClientScript.RegisterStartupScript(GetType(), "CloseScript", 
  "window.opener.location.reload(); window.close();", true);

Upvotes: 0

Related Questions