HELP: Spawning Multiple Browsers Using RegisterClientScriptBlock

K

kewl

Hi All,
We have an ASP.NET 2.0 (C#) intranet application that needs to spawn multiple browsers using RegisterClientScriptBlock. Here's what we got so far:

// Go thru each datarow in the datatable
foreach (System.Data.DataRow drReportGroupsDetails in tableReportGroupsDetails.Rows)
{
// Get the needed values from the datatable
string reportName = (string)drReportGroupsDetails["ReportName"];
string reportPath = (string)drReportGroupsDetails["ReportPath"];

// Do other work ...

// Build the URL - NOTE: The reportName and reportPath variables are different each time thru the loop
url = "http://localhost/..." + reportName + "..." + reportPath + "...";

// Build the javascript to display the message
sScript = "<script language=\"javascript\" type=\"text/javascript\">window.open(\"" + url + "\", \"GenerateReport\", \"height=675,width=975,left=0,top=0,copyHistory=no,directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no\");</script>";

// Execute the script
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "GenerateReport", sScript);
}


So, we have a method that iterates through a set of rows in a datatable, builds a URL, builds the JavaScript to open a new window (using window.open), and then executes the script using Page.ClientScript.RegisterClientScriptBlock.

The problem is that only one browser is popped-up. It's for the last row in the datatable.

How can we pop-up a new browser instance for each row in the datatable?

Thanks.
 
M

Marina Levit [MVP]

Give the script blocks unique names. It looks like the name is always GenerateReport - so it keeps overwriting the last script, and you end up with the very last one.

If you look at the documentation for RegisterClientScriptBlock it says:
A client script is uniquely identified by its key and its type. Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page. Attempting to register a script that is already registered does not create a duplicate of the script.

Call the IsClientScriptBlockRegistered method to determine whether a client script with a given key and type pair is already registered and avoid unnecessarily attempting to add the script.


Give the scripts unique names. For example, use an integer that you increment to create script names like GenerateReport0, GenerateReport1, etc.
Hi All,
We have an ASP.NET 2.0 (C#) intranet application that needs to spawn multiple browsers using RegisterClientScriptBlock. Here's what we got so far:

// Go thru each datarow in the datatable
foreach (System.Data.DataRow drReportGroupsDetails in tableReportGroupsDetails.Rows)
{
// Get the needed values from the datatable
string reportName = (string)drReportGroupsDetails["ReportName"];
string reportPath = (string)drReportGroupsDetails["ReportPath"];

// Do other work ...

// Build the URL - NOTE: The reportName and reportPath variables are different each time thru the loop
url = "http://localhost/..." + reportName + "..." + reportPath + "...";

// Build the javascript to display the message
sScript = "<script language=\"javascript\" type=\"text/javascript\">window.open(\"" + url + "\", \"GenerateReport\", \"height=675,width=975,left=0,top=0,copyHistory=no,directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no\");</script>";

// Execute the script
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "GenerateReport", sScript);
}


So, we have a method that iterates through a set of rows in a datatable, builds a URL, builds the JavaScript to open a new window (using window.open), and then executes the script using Page.ClientScript.RegisterClientScriptBlock.

The problem is that only one browser is popped-up. It's for the last row in the datatable.

How can we pop-up a new browser instance for each row in the datatable?

Thanks.
 
B

Bruce Barker

also for this to work, your clients will have to allow popups in their browser.

-- bruce (sqlwork.com)

Give the script blocks unique names. It looks like the name is always GenerateReport - so it keeps overwriting the last script, and you end up with the very last one.

If you look at the documentation for RegisterClientScriptBlock it says:
A client script is uniquely identified by its key and its type. Scripts with the same key and type are considered duplicates. Only one script with a given type and key pair can be registered with the page. Attempting to register a script that is already registered does not create a duplicate of the script.

Call the IsClientScriptBlockRegistered method to determine whether a client script with a given key and type pair is already registered and avoid unnecessarily attempting to add the script.


Give the scripts unique names. For example, use an integer that you increment to create script names like GenerateReport0, GenerateReport1, etc.
Hi All,
We have an ASP.NET 2.0 (C#) intranet application that needs to spawn multiple browsers using RegisterClientScriptBlock. Here's what we got so far:

// Go thru each datarow in the datatable
foreach (System.Data.DataRow drReportGroupsDetails in tableReportGroupsDetails.Rows)
{
// Get the needed values from the datatable
string reportName = (string)drReportGroupsDetails["ReportName"];
string reportPath = (string)drReportGroupsDetails["ReportPath"];

// Do other work ...

// Build the URL - NOTE: The reportName and reportPath variables are different each time thru the loop
url = "http://localhost/..." + reportName + "..." + reportPath + "...";

// Build the javascript to display the message
sScript = "<script language=\"javascript\" type=\"text/javascript\">window.open(\"" + url + "\", \"GenerateReport\", \"height=675,width=975,left=0,top=0,copyHistory=no,directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no\");</script>";

// Execute the script
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "GenerateReport", sScript);
}


So, we have a method that iterates through a set of rows in a datatable, builds a URL, builds the JavaScript to open a new window (using window.open), and then executes the script using Page.ClientScript.RegisterClientScriptBlock.

The problem is that only one browser is popped-up. It's for the last row in the datatable.

How can we pop-up a new browser instance for each row in the datatable?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,734
Latest member
manin

Latest Threads

Top