I have a WebDialogWindow which displays a ContentURL.On the ContentURL form, I have a button. How do I close the WebDialogWindow when I click the button on the ContentURL from?
Hello,
I played a bit with the scenario and was able to make this work. Here is my setup - I start with a WebDialogWindow instance in one page (Default.aspx) and then set the ContentPane - ContentUrl property to point to another page:
<ig:WebDialogWindow ID="WebDialogWindow1" runat="server" Height="300px" Width="400px"> <ContentPane ContentUrl="default2.aspx"> </ContentPane> </ig:WebDialogWindow>
In the content Default2.page, I have the following script and content:
<script language="javascript"> function closeWindow() { var dialogWindow = this.parent.$find("WebDialogWindow1"); dialogWindow.hide(); } </script> <a href="#" onclick="closeWindow()">Close Parent Window</a>
So basically, the idea is to look for the "parent" property of the content window. The really tricky part is that sometimes the ClientID of the dialog window will not be equal to the server ID. So, you may need to store the client ID of the window in a hidden field in the parent page, e.g.
<input type=hidden id=windowClientID value=<%= WebDialogWindow.ClientID %> />
and then get it from the content page and use it as an ID.
Thanks Rumen, however, I have a "Send Mail" button on my page that runs server side code to send an email. So when the email is sent, I would like to close the webdialog from the server side code...any ideas?
From the server it will be hard, since the DialogWindow operates on client, but I guess you can using the Page.ClientScript.RegisterClientScriptBlock (or RegisterStartupScript) to emit javascript similar to the one above that will close the window when the page reloads next.
Will this work?
So, just to make sure I understand, you want to first close the window, then execute postback?
calling _doPostBack is possible, if you can emulate the EVENTTARGET and EVENTARGUMENTS the framework is generating for the button. Or you can call the click() function of the button, e.g.
<asp:button runat="server" ID="Button1" OnClick="ServerSideFunction" />
<script type="text/javascript">
var button = document.getElementById("<%= Button1.ClientID %>");
button.click()
</script>
Alright - this seems like a great idea - thanks for sharing in public forums - this will certainly help other people, since this seems like a common scenario (closing window from child page and then executing postback logic).
I will try to have this covered in samples/help or DevCenter as well.
Rumen I found a work around. I use 2 buttons on the form. One for "Send" and one to "Close"The Close button uses the Clientside script. However, when the message is successfully sent I give them a webdialog confirmation in the webdialogwindow which clears the email form and essentially resets the form!
This will probably not work since the first page will never be reached when you click "Send" - it will go to second page and return there. The only solution I see is to register javascript from server using
Page.ClientScript.RegisterStartupScript and execute javascript that will close the window (using the javascript code I sent you before). I think this will work.
The other possible idea is to first close the window with javascript (using again the same code) and then do the "Send" postback - this can be done using the "click()" button idea I send you (or you can use LinkButton and handle OnClientClick)
Rumen, once I click the button and the email is sent I want to close the window. Is there no way cast the page.previous or page.parent and get the webdialogwindow and run webdialogwindow1.windowstate=hidden?