Link to home
Start Free TrialLog in
Avatar of wframsay
wframsay

asked on

Opening Windows Programmatically from Code Behind

I have an ASP.NET 2.0 application that is generating a number of HTML files in a code behind file. For each of these HTML files I would like to open a new browser window (the HTML files are reports). I have tried using javascript and have been unable to get the window to open up.



Avatar of ChetOS82
ChetOS82
Flag of United States of America image

What are you doing in Javascript?  After the HTML files are created, generate a window.open(url); line in the javascript, when the page loads it should execute all of them and open the windows.
Avatar of wframsay
wframsay

ASKER

I do not know how many files are going to be generated (it's based on user entry). Ideally I would open each of the HTML files in a window as each item is processed (some items do not generate reports, others do, so there could be 10 reports to display or just 1 or even 0).

How do I "generate a window.open(url) line in javascript" for multiple files?
ASKER CERTIFIED SOLUTION
Avatar of samtran0331
samtran0331
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The report files that are generated have to be kept on the server, rather than just displayed and then discarded, so I do not think this solution will work for me. Thank you for the effort, though.
wframsay,

i think samtran0331's idea might work 4 u actually!
how do you get the generated html reports? a url link or the html stream?
I agree that the solution would work if I were able to display them as they were generated, however we are required to store the files for future reference, so I need to create actual html files. For the purposes of the demo I am putting together I am using something similar to the suggestion provided.
For the purposes of the demo I am putting together I am using something similar to the suggestion provided, so I'm accepting the solution provided.
>>however we are required to store the files for future reference, so I need to create actual html files.

That being the case, you can still use the loop like in my example, but then the js function would be more like what ChetOS82 eluded to.

the loop would be driven by whatever logic you have to determine which reports are shown and would be more like:

    protected void Page_Load(object sender, EventArgs e)
    {
        string StrPageURL = "";
        for (int i = 0; i <= 4; i++)
        {
            StrPageURL = "somepagename.html"; //be sure to set the path correctly
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript" + i.ToString(), "<script language=\"javascript\">openDynamicPage('" + StrPageURL + "','" + i.ToString() + "');<" + "/script>");
        }
    }


And the js would be:
    <script language="javascript" type="text/javascript">
      function openDynamicPage(htmlURL,winID)
      {
            window.open(htmlURL,"DynamicPage"+winID);
      }
    </script>



ultimately, the trick to opening multiple windows is the "winID" in the js function, as long as each iteration has a unique winID, the browser will open a new window...