views:

3059

answers:

4

Using ASP.Net 2.0

a. On a parent ASPX page, after a HyperLink control is clicked, I need to open a (child) page in a popup window, as modal.

b. Then when that popup window (child page) is closed, I need to get the selections from a datagrid on that popup window and refresh the parent page accordingly.

c. I have open window javascript code in a javascript.js file, which I am loading like this:

protected void Page_Load(object sender, EventArgs e)
{
  ClientScript.RegisterClientScriptInclude(this.GetType(), "manualequipentryscript", "javascript.js");
  lnkSearchProducts.Attributes.Add("onclick", "LaunchProductSearch();");
}

..isn't working..

How do I implement this?

( I searched the www for the past 2 hours and came up with so many results by haven't been able to get anything concrete that would help me. )

Regards, Bob

+1  A: 

The first thing to understand is that browsers generally do not allow true modal popup windows (with the notable exception of IE). Mozilla based browsers allow you to specify that a window will remain in front, but that cannot be considered modal. This article expands on this actuality.

The usual workaround is to display a Modal dialog in a DIV instead of another window.

Secondly, in order to pass values from a popup window to the parent window, you can either use Javascript methods or server side code. The former method would involve first accessing the parent window (using the window.opener property) and then retrieving references to elements within that parent window. See this article for an example.

The server side method would require you to persist state values and then force a Javascript refresh of the parent window (using window.opener.location.reload();) to enable those values to be loaded.

Finally, the code you have presented seems about right to me. Tell us the error message you get... that may provide a clue.

Cerebrus
A: 

@Cerebrus :

Thank you Cerebrus for responding..

I will implement the second method ie. to persist state values and cause a reload of the parent page - as it is easier.

The problem is that while it opens the page, it does not open as a popup window ie. I see the browser location bar..

  1. This is the contents of the javascript file:

var ProductSearchWindow = null;

function closeProductSearch(){ if((ProductSearchWindow) && ProductSearchWindow != null){ ProductSearchWindow.close(); ProductSearchWindow = null; } }

function LaunchProductSearch(){
if(!ProductSearchWindow) { ProductSearchWindow = window.open("ProductSearch.aspx", "Product Search", "location=0, menubar=1, toolbar=0, resizable=1, scrollbars=1, titlebar=0, left=30, top=100, height=490, width=670"); } else { if(ProductSearchWindow == null) { ProductSearchWindow = window.open("ProductSearch.aspx", "Product Search", "location=0, menubar=1, toolbar=0, resizable=1, scrollbars=1, titlebar=0, left=30, top=100, height=490, width=670"); } else { if(ProductSearchWindow.closed) ProductSearchWindow = window.open("ProductSearch.aspx", "Product Search", "location=0, menubar=1, toolbar=0, resizable=1, scrollbars=1, titlebar=0, left=30, top=100, height=490, width=670"); else if(ProductSearchWindow.focus){ ProductSearchWindow.focus(); } else { // do nothing } } } }

  1. ..and this is the NavigateUrl property on the HyperLink control: ~/ProductSearch.aspx

The thing is - it is using this property to open the page in a new window. ..which is not what I want. I want it to open as a 'popup' window, and using the javascript "LaunchProductSearch();" call in my original post.

-Bob

A: 

For what it's worth, the site is a Master Pages site. The problem is that the page cannot see the script file or there is some kind of problem. Anyone?

A: 

Basically my question is:

Has anyone had success adding an external javascript file to a ASP.Net 2.0 Master Pages site? How?