Solved

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

Posted on 2012-03-09
2
898 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
[X]
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
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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

705 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