Link to home
Start Free TrialLog in
Avatar of dwoolley3
dwoolley3Flag for United States of America

asked on

How to open a new window in ASP.NET/C# code behind without full page postback

I am able to dynamically write JavaScript routines in my ASP.NET/C# code behind page in order to open a new window. However, I notice that this is only done when there is a full page postback. When I try to perform the following code segments in a method like FormView1_ItemInserted(), and the FormView is within an AJAX Panel, then the JavaScript is not executed, it seems.

ClientScript.RegisterClientScriptBlock(this.GetType(), "anything2", strScript.ToString());

ScriptManager.RegisterStartupScript(Page, this.GetType(), "Open Window", strScript.ToString(), true);

The strScript contains the JavaScript code surrounded by the <script> tags.

While I am specifically wanting to open a new window dynamically, I am wanting to be able to execute any JavaScript code (e.g. an alert) to do something after I insert a record into a formview, surrounded by an AJAX Panel Update. Just prior to executing the new window, I am dynamically creating 3 html files and the 3rd file will be the one that I am opening in the new window (which will link to the other 2 html files).
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
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
Avatar of dwoolley3

ASKER

Since strScript has the <script> tags, I needed to change the last parm to "false", and now it works!

ScriptManager.RegisterStartupScript(this, this.GetType(), "Open Window", strScript.ToString(), false);

Evidently, I was wrong it thinking that the JavaScript routine would not work in an AJAX Panel Update, based on my experiments. Thanks for the correction to the last parm.