Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2012-03-09
2
853 Views
Last Modified: 2012-06-21
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).
0
Comment
Question by:dwoolley3
2 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 37703064
This is the correct way to do this:
ScriptManager.RegisterStartupScript(this, this.GetType(), "Open Window", strScript.ToString(), true);

if strScript already has the <script> tags, set the last parameter to false.

If you wanted to do it clientside, you could either add an attribute for onclientclick passing the script or just add the onclientclick attribute directly to your aspx page.

Not sure exactly what your question is though.
0
 

Author Closing Comment

by:dwoolley3
ID: 37703134
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.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question