Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with removing item from Session Array 3 24
What Does This C# Code Block Do? 5 30
innerHTML 7 20
c# - Best approach for objects in functions 3 16
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

809 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