Solved

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

Posted on 2012-03-09
2
831 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 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now