opening new window from code behind using javascript


I am trying to open new window when i click on a button using javascript

Page.ClientScript.RegisterStartupScript(this.GetType(), "openwindow", "'WebForm2.aspx','','height=200,width=300');", true);

this is the code i am using.

But the problem is it postsback whole page.

Can some body tell me how i can open new window without posting back the page.



2/19/2008 9:48:35 AM 24353 articles. 2 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 45
Get it on Google Play
Get it on Apple App Store

 Hi Vinod,

Do you use a scriptmanager on your page?

If so, then you should use the RegisterStartupScript method of the ScriptManager class (= ScriptManager.RegisterStartupScript(.....       )


If you have questions/remarks please do so!

Kind regards,

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
2/19/2008 10:33:11 AM


try using



Software Engineer
2/19/2008 10:38:36 AM


You can use the HTML button control instead of the server control to avoid postbacks.

Alternatively check this link. 

Suprotim Agarwal


ASP.NET Grid With Excel Capabilities | 27 GridView Tips & Tricks | Hosting your site? | SQL Server Tips
2/19/2008 10:42:45 AM

   Try this way .

                     Step 1. write java script in aspx.

                             <script language="javascript">
                                               function test()

                   Step 2. In the Page load [Codebehid] Register this

                             in the Page Load

                              Button1.Attributes.Add("onclick","return Test()");

                               //Here Buttin1 is Server side Control

      Thanks and regards







2/19/2008 10:46:25 AM

Instead of this:
     Page.ClientScript.RegisterStartupScript(this.GetType(), "openwindow", "'WebForm2.aspx','','height=200,width=300');", true);

if the window is to be opened on the click of a button, use this:
     Button1.Attributes.Add("onclick", "'WebForm2.aspx','','height=200,width=300');", true); return false;");

The important thing, to stop the PostBack, is the return false; part.


2/19/2008 1:32:13 PM

Similar Artilces:

I am using a client side javascript to open a new window and have a problem
I have a user control..On it i have the word 'open' as a link....calling my javascript to open another page.....This page then auto close with javascript...Problem is when you click on 'open' it brings up my page and another page do you avoid this???? hello, u would like to check my article on the following address: Pop Up Window from inside ASP.NET best of luck.Bilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

Problem with opening new window "window.Open" using javascript
I am trying to open new window when press a button "btnPrint" using: Response.Write("<script language='javascript'>'CouponReport.aspx', 'window', 'HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes'); </script>"); but when the new window opened the current page do a post back action and the current page format change like the following: before window open: after window opened: So, how i can a void the post back action.  <script language='javascript'> funct...

Open new window with javascript from code behind file
What do I have to change to get the line in comment working ?Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click   Page.Validate()   If (Page.IsValid) Then      If Textbox1.Text <> "" Then         UpdateButton_Click(Button1, e)      Else         InsertButton_Click(Button1, e)      End If      'Response...

Opening a new browswer window using code behind
I have an ASP.NET application with the code behind written in C#. I'm trying to figure out how to open a new browser window when a user selects a menu option. Right now I have the command: Response.Redirect("documents/Employee.pdf"); The problem is that this opens the pdf in the same browser window when, instead, I would like to open the pdf in a new browser window. How can I do this? Thanks! I am not sure what you mean by 'selects a menu option' - so I am presuming that you mean a button.You cannot open a new window from the code behind as it is server side only. You can, however, att...

Using C# code behind to open a new Internet Explorer window
I'm using the Response object to stream pdf document to the browser when a user hits a particular button on a page. This is working correctly, however the pdf opens in the same browser window. How do I open a new (second) browser window and stream the output to this new window? Thanks! You have to use client side code (javascript) to open a new IE window. You can call the javascript after server side code executed.This posting is provided "AS IS" with no warranties, and confers no rights. Hi, first check out this code sample: Open a popup window after a button click After reading you...

Calling a Form Code-Behind function using Javascript from the Client Side
Hi,Is there any way to call a function in the form codebehind from the client side using javascript? If yes, how? How to send parameters?Thanks. Try reading this article.  It is kind of the opposite of what you are trying to do but maybe it will help. this helps,MattADV do a view source on the page and you most liekly will see a do post back function. You can call that with JavaScript and it forces the page back. You can send parameters back by placing them inside of hidden form e...

finding server control, in the code behind, created from client side using javascript
Hi experts   i wanna add server side controls using javascript and access it in code behind but i am not able to access it can u give me the solution example javascript file function AddControl() { var table=document.createElement('table') var tr=document.createElement('tr') var cell1=document.createElement('td') cell1.innerHtml='<input type="text" ID="txtSample" runat="server"/> tr.appendChild(cell1) table.appendChild(tr); }   if i try to get this control in code behind like this i am not able to get ...

how to open a window using javascript like opening a new IE
Is there anyway to open a new window using javascript or which act like a fresh new window? I have an program consists of datagrid. There is a column consists of link button. When user click the linkbutton, I want to set some cookies and the open a new window. However, when I click another link in the datagrid, the cookies will be changed, and the cookies in the previous open window also being changed. Somehow, the page is linked with the parent. If the cookies is changed, the cookies in new window also changed. Is there anyway to solve this? I use javascript win...

Hi, can any eagle eyed geniuses spot what I'm doing wrong here? It's doing my nut! I'm simply trying to call a new page in a new window that I want to control the size, etc. I've tried two different ways - one from within my code behind and the other triggered by a LinkButton command action. Both do absolutely nothing. Please help... Private Sub InfoClick1(ByVal pSiteCode) Response.Write("<script>'siteinfo.aspx?sitecode='" & pSiteCode & "','Info','left=20,top=20,height=500,width=850,toolbar=no,status=no,resizable=1,scrollbars=no')</script>") End Sub +...

How to use client-side script(javascript) in DNA using .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script> objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ...... }   szUrl = "http://ServerNa...

how to open popup window through javascript in code behind( popup window should be aligned center)
I want to use javascript in code behind to open popup window. I have Datalist inside which there is linkbutton. On click of linkbutton open popup window through javascript & that pop up window should be aligned centraly.Regards,Mahesh--------------------click "Mark as Answer" on the post that helps you. Friend, Try this sample . <html xmlns="" ><head runat="server">    <title>Untitled Page</title>        <style>    .blue{ bac...

Session lost in opening a new popup window using javascript OR on using hyperlinks target=_blank attribute
 I am opening a pop window using javascript and loading an .aspx page in it.But the Session variable is losing the value set into it ,in the aspx.cs file of the parent window. And thus I am not getting the value back from session the aspx.cs loaded into pop up window. Instead of javascript I tried to achieve the same using hyperlink field, opening the window using target="_blank" into a new browser.But again the session variable values are lost. I have to use only Session object for getting this done.  If anyone has done this before,please helpGive it One More try..Untill K...

Opening a new window in a new window using java script
I have an application where I need to open a new window and in that opened new window a button will be there clicking on which I have to open the other new window. I did in the normal way i.e,'../NWINNW/FirstWindow.aspx','mywindow','width=730px,Height=290px,left=100px,top=100px,scrollbars=yes'); in the default page and'../NWINNW/SecondWindow.aspx','mywindow','width=730px,Height=290px,left=100px,top=100px,scrollbars=yes'); in the first window page. The first opens correct but the second window is opening in the sa...

Opening a new window from the code behind
Hi, On my web page I have a button which runs some code to update values. At the start of this code in the code behind I'd like to open another web page and another at the end of the updates but I can't work out how I do that. I've gota javascript statement on my client side code, do I need to do something similar on the code behind ? Thanks for any help.  hi, I assume someone clicks on the button on page 1? Button1.Attributes.Add("onclick", "'Page2.aspx','popWin','width=300px,height=200px');"...

Web resources about - opening new window from code behind using javascript -

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

JavaScript - Wikipedia, the free encyclopedia
programming styles. JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
... editor - report abuse/spam - help the entire directory only in Tools/Obfuscators Description Top : Computers : Programming : Languages : JavaScript ...

Facebook Open-Sources JavaScript Static-Type Checker Flow
The latest software to be open-sourced by Facebook is Flow , a static-type checker for JavaScript . (more…) New Career Opportunities Daily: ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing ...

Facebook App Devs Get Javascript
It has been an oft-lamented fact of the Facebook Platform thus far in its life that, in order to use all but the most simple of Javascript functionality–the ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken .… ...

Resources last updated: 11/28/2015 2:48:34 PM