How can I update an asp update panel from my dialog window and close the dialog window? Can I do this in the code behind? I need a sample.
Thanks in advance.
Hi,
If I understood correctly you have a trigger element (to close dialog), which is located inside of aspx and that aspx is used as ContentUrl for dialog. If it is the case, then you should should keep in mind that javascript for a trigger element belongs to different window. So, you need find reference to the main window and from that window you can find reference to dialog. You may try "parent", "top", etc. Below is example:
<script type="text/javascript">function closeDialog(){ var win = window.parent; if(!win || !win.$find) win = window.top; if(!win || !win.$find) return; var dialog = win.$find('WebDialogWindow1'); if(dialog) dialog.hide();}</script><input type="button" value="Close Dialog" onclick="closeDialog()" />
Focusing on the hide, I have this js code below and an anchor tag that calls it. This is in the web dialog window. FWIW, my webdialogwindow is another aspx page. JS produces null ever time for WebDialogWindow1 even if i do this.parent.$find or just $find.
<script language="javascript">function closeDialogWindow(){ $find('WebDialogWindow1').hide();}</script>
and an anchor tag that calls it.
<
a href="#" OnClick="closeDialogWindow();"><span style="font-size:x-small;">Cancel</span></a>
You can do it in the code behind, or in JavaScript. Either way has it's advantages/disadvantages. UpdatePanel can't be refreshed via client-side without a 'hack'. Posting the entire page back to the server, just to hide the dialog negates having the update panel there in the first place though.
My recommendation, do this on the client-side. You can show and hide the WebDialogWindow through the client-side API. It's actually rather straight forward. Add a button to your dialog window, and one to your UpdatePanel, and hook up the button in the WebDialogWindow's onclientclick event. When the button is clicked, call the WebDialogWindow's hide function (webDialogWindow1.hide()) and then call the other button's click event. So if the button you put in the UpdatePanel was button2 your javascript function would be something like
function OnButtonClick(){$find("webDialogWindow1").hide();$get("button2").click();}
By calling the second button's click event, you will force it to perform a postback, which will be captured by the UpdatePanel, and turned into an AJAX callback.
-Tony