Quote:
Originally Posted by vinod allapu
Is the process of checking the page is popup or not can be done in cs file using this.page.parent?
No.
Your C# code knows nothing about browser windows. Browser windows are opened and dealt with client side, not server side. Your C# code runs on the server and has no idea about the relationship between browser windows....how could it?
You opened your child window using JavaScirpt right?
You have something like:
-
<script type="text/javascript">
-
function OpenAuthorWindow(){
-
window.open("Authors.aspx","ManageAuthors", "toolbar=no, menubar=no, width=980, height=550, resizable=yes, scrollbars=yes");
-
-
return false;
-
}
-
</script>
And you call this from your button like:
-
<asp:Button id="manageAuthors" onclientclick="return OpenAuthorWindow();" Text="Add Author"/>
Or something like:
-
manageAuthors.Attributes.Add("onclick","return OpenAuthorWindow();");
Anyways, you have code that opens the child window.....
You're going to need at least 2 more JavaScript functions to make this work: one in the parent window that updates the DropDownList, and one in the child window that calls the JavaScript function in the parent window when the user is finished adding a new Author.
Let's start with the JavaScript that updates the DropDownList.
I would place the DropDownList in an UpdatePanel so that when it is updated it doesn't cause the whole page to update.
Now here's a little trick to get it to update.
Place a LinkButton or a Button in the same UpdatePanel as the DropDownList, give it an ID and set it's css style to Display:None so that it's invisible to the user:
-
<asp:UpdatePanel id="DropDownListUpdateSection" runat="server" UpdateMode="Conditional" >
-
<ContentTemplate>
-
<asp:DropDownList id="authorsList" runat="server"></asp:DropDownLIst>
-
<asp:Button id="updateAuthorsList" runat="server" text="update authors" style="display:none;" />
-
</ContentTemplate>
-
</asp:UpdatePanel>
-
Now write a JavaScript method that calls the JavaScript __doPostback method for the button:
-
<asp:UpdatePanel id="DropDownListUpdateSection" runat="server" UpdateMode="Conditional" >
-
<ContentTemplate>
-
<asp:DropDownList id="authorsList" runat="server"></asp:DropDownLIst>
-
<asp:Button id="updateAuthorsList" runat="server" text="update authors" style="display:none;" />
-
-
<script type="text/javascript">
-
function UpdateAuthorsList() {
-
__doPostBack('<%=updateAuthorsList.ClientID %>', '');
-
}
-
</script>
-
</ContentTemplate>
-
</asp:UpdatePanel>
-
Ok, so now we have a JavaScript function that causes a hidden button to postback to the server.
You need to implement a method that handles the hidden button click event so that it re-populates the Authors DropDownList when it is clicked.
After you're done with that, you need to move to the Authors Editing page (the page that will be opened in the child window).
You need to implement a JavaScript method that calls the JavaScript method we just implemented.
After trying this out myself in many browsers, here's the code that will work:
-
<script type="text/javascript">
-
//You must use the setTimeout method in both of the following functions
-
//in order for the main page to be updated in FireFox version 2.
-
-
//window.onbeforeunload = updateParent;
-
function updateParent() {
-
try {
-
if (window.opener && !window.opener.closed) {
-
var win = window.opener;
-
window.opener.setTimeout(win.UpdateAuthorsList, 100);
-
}
-
} catch (err) { }
-
}
-
// function CloseBrowserWindow() {
-
// window.close();
-
// }
-
</script>
-
This code checks whether or not a parent page exists before attempting to call the JavaScript that updates the DropDownList. If the parent page doesn't exist, it doesn't do anything. You just have to call this method whenever you need it.
You'll notice some code that has been commented in the above posted JavaScript snippet. If you uncomment this code the method will be called whenever the page is unloaded (whenever a full page postback happens, or if the user leaves the website, or if the
window is closed). This does not work in the Opera web browser though because it doesn't support the onbeforeunload JavaScript event. You can call this method during any event though...like a button click event for instance.
Hope this helps.
-Frinny