473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

open a javascript window from code behind

Hi all, how do I open a javascript window from a code behind page?
I was using

Response.Write("<script
language='javascript'>window.open('url','name','op tions');</script>")

but now for some reason it is not working..
Thanks in advance
Mark

Nov 18 '05 #1
5 3367
Hi Mark,

You can try this....

After your form tag in your aspx file type the folloowing

......
</form>
<script language="javascript">
<asp:literal runat="server" id="ltScript"></asp:literal>
</script>

In your code behind do the following
Literal ltScript = (Literal) Page.FindControl("ltScript");
ltScript.Text = "window.open('http://MyURL/MyPage.aspx','name','options');"

Regards
Ganesh

"Mark" <ma**@Z-Zvolution.nZt> wrote in message
news:cl**********@lust.ihug.co.nz...
Hi all, how do I open a javascript window from a code behind page?
I was using

Response.Write("<script
language='javascript'>window.open('url','name','op tions');</script>")

but now for some reason it is not working..
Thanks in advance
Mark

Nov 18 '05 #2
Hi Ganesh, thanks for that info. I tried it but it is still not working. It
must be a problem with my spyware / browser setup stopping scripts as your
code looks fine.

Thanks again
Mark
--

"Ganesh Ramamurthy" <ga****@kottsoftware.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
Hi Mark,

You can try this....

After your form tag in your aspx file type the folloowing

.....
</form>
<script language="javascript">
<asp:literal runat="server" id="ltScript"></asp:literal>
</script>

In your code behind do the following
Literal ltScript = (Literal) Page.FindControl("ltScript");
ltScript.Text = "window.open('http://MyURL/MyPage.aspx','name','options');"
Regards
Ganesh

"Mark" <ma**@Z-Zvolution.nZt> wrote in message
news:cl**********@lust.ihug.co.nz...
Hi all, how do I open a javascript window from a code behind page?
I was using

Response.Write("<script
language='javascript'>window.open('url','name','op tions');</script>")

but now for some reason it is not working..
Thanks in advance
Mark


Nov 18 '05 #3
Hi Mark,
Check if you have any popup blocker installed in your browser. Also winxp
service pack 2 comes with a popup blocker.
HTH
srini

"Mark" wrote:
Hi all, how do I open a javascript window from a code behind page?
I was using

Response.Write("<script
language='javascript'>window.open('url','name','op tions');</script>")

but now for some reason it is not working..
Thanks in advance
Mark

Nov 18 '05 #4
are you able to do the same using plain Javascript??

"Mark" <ma**@Z-Zvolution.nZt> wrote in message
news:cl**********@lust.ihug.co.nz...
Hi Ganesh, thanks for that info. I tried it but it is still not working. It must be a problem with my spyware / browser setup stopping scripts as your
code looks fine.

Thanks again
Mark
--

"Ganesh Ramamurthy" <ga****@kottsoftware.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
Hi Mark,

You can try this....

After your form tag in your aspx file type the folloowing

.....
</form>
<script language="javascript">
<asp:literal runat="server" id="ltScript"></asp:literal>
</script>

In your code behind do the following
Literal ltScript = (Literal) Page.FindControl("ltScript");
ltScript.Text =

"window.open('http://MyURL/MyPage.aspx','name','options');"

Regards
Ganesh

"Mark" <ma**@Z-Zvolution.nZt> wrote in message
news:cl**********@lust.ihug.co.nz...
Hi all, how do I open a javascript window from a code behind page?
I was using

Response.Write("<script
language='javascript'>window.open('url','name','op tions');</script>")

but now for some reason it is not working..
Thanks in advance
Mark



Nov 18 '05 #5
Hi Mark,
i had the same problem as you and I found a little workaround...

just add a normal <asp:Button id=someButton runat=server></asp:Button>
in code behind

on the page load add this line

this.someButton.Attributes.Add("onClick",
"window.open('popupwindow.aspx','WindowName','tool bar=0,scrollbars=1,location=0,statusbar=1,menubar= 0,resizable=1,width=640,height=425');");
now the flow that happens is ..
1) the popup window is openened ...
2) the code behind for the first page is triggered

you can add <body onload="window.focus()"> to the body onload event of
your popup but the first page will be on top even with this code.

a workaround for this is to add this piece of javascript

<body onload="window.focus()" onblur="blurEvent()">

<script language="javascript">
var count = 0;

function blurEvent()
{
if(count == 0)
self.focus();
count = count + 1;
}
</script>
downside :
if the postback triggered stuff thats write to session or database ..
it will not be accessible on the first pageload of your popup page.
but you could adapt the blurEvent() function so it postsback the first
real load ... (count == 1)

Is it a nifty or nasty workaround ... i'll leave that up to you, but
it did help me out :)

Greets,
Tom
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lukeo | last post by:
I'm shelling out to an .asp (or htm) page from an application. I want to show this in a window without the address bar, etc... Is there a way I can redirect this page using javascript to a page...
1
by: Nevyn Twyll | last post by:
I have a DataList; in the DataList's , I have a LinkButton and a few listboxes. When the LinkButton is pressed, I need to get the ID of the selected item in one of the Listbox controls. Then I...
8
by: J Gao | last post by:
Hi, experts, On a button click, I need to save some data to the session object. Then open a new window. The new window will use the session data saved in the first window. I don't want use to...
2
by: mg | last post by:
window.open (URLTarget, windowName, height=720,width=975,resizable=yes, ... lets me open a new WebForm with a specified size using JavaScript. Is there a way of doing this from code behind;...
2
by: Chris | last post by:
I know this is a dead horse I'm beating but why is it so impossible to ask for functionality in the HTML tag to open a window/page more controllable? why is: <a href="somepage.aspx?value1=xyz"...
2
by: carlor | last post by:
Hi there, I have a form that contains a link button. When the user clicks the link button I need to enable a couple of other buttons on the page and open a new browser window giving it focus...
9
by: loga123 | last post by:
I am using asp .net 2.0. I have a hyperlink asp control on my web page page1.aspx. On clicking this hyper;link, I would like to open page2.aspx (which is in the same web application) in a new IE...
5
by: rockdale | last post by:
Hi, all: I have a linkbutton and I use javascript to open another webpage in a new window. I also want to set my session variable value when this linkbutton get clicked. These session variable...
6
by: bushi | last post by:
hi everyone! i have diplayed my hyperlinks in a iframe.when i redirect to next page.the next page also open in the same frame,but i want to open a new browser window,when i click on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.