473,732 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to open a new window in button click event?

hb
Hi,

I have a asp:button btnGo. When clicking this button,
the code will parse a asp:table to find a specific ID
under certain conditions. Once the ID is found, the code
need to keep the current page open and to redirect the
user to a newly opened browser window with a link like:
http://www.mydomain.co m/tellme.aspx?cli entID="+ID

But the Response.Redire ct(URL) opens a new page in the same
window.

Someone suggested to insert a JavaScript function to button's
OnClick event. But this insertion needs to be done in Page_Load().
And the parameter the target url needs is not available yet at
page load time.

If I insert the window.open() JavaScript in btnGo_Click() event,
the window.open JavaScript will only be available after first click
event.

I also thought of asp:hyperlink control. It does have a target property
and can not fire any event on server side.

Would you please give some work around idea regarding what I
want to do?

Thank you

hb
Nov 18 '05 #1
3 29107
current browser security settings require that a window only be opened from
href with a target, or client script tied to a onclick event. this prevents
the old trick of spewing inline javascript to open the window.

you need to find another approach. you should pass the id down in the
original render, and have client script determine the correct value, or just
render a link the user clicks on to open the window.

-- bruce (sqlwork.com)
"hb" <ho****@goodoff ices.com> wrote in message
news:uV******** ******@TK2MSFTN GP09.phx.gbl...
| Hi,
|
| I have a asp:button btnGo. When clicking this button,
| the code will parse a asp:table to find a specific ID
| under certain conditions. Once the ID is found, the code
| need to keep the current page open and to redirect the
| user to a newly opened browser window with a link like:
| http://www.mydomain.co m/tellme.aspx?cli entID="+ID
|
| But the Response.Redire ct(URL) opens a new page in the same
| window.
|
| Someone suggested to insert a JavaScript function to button's
| OnClick event. But this insertion needs to be done in Page_Load().
| And the parameter the target url needs is not available yet at
| page load time.
|
| If I insert the window.open() JavaScript in btnGo_Click() event,
| the window.open JavaScript will only be available after first click
| event.
|
| I also thought of asp:hyperlink control. It does have a target property
| and can not fire any event on server side.
|
| Would you please give some work around idea regarding what I
| want to do?
|
| Thank you
|
| hb
|
|
Nov 18 '05 #2
hb
I see. Thank you.

hb
"bruce barker" <no***********@ safeco.com> wrote in message
news:uc******** ******@TK2MSFTN GP14.phx.gbl...
current browser security settings require that a window only be opened from href with a target, or client script tied to a onclick event. this prevents the old trick of spewing inline javascript to open the window.

you need to find another approach. you should pass the id down in the
original render, and have client script determine the correct value, or just render a link the user clicks on to open the window.

-- bruce (sqlwork.com)
"hb" <ho****@goodoff ices.com> wrote in message
news:uV******** ******@TK2MSFTN GP09.phx.gbl...
| Hi,
|
| I have a asp:button btnGo. When clicking this button,
| the code will parse a asp:table to find a specific ID
| under certain conditions. Once the ID is found, the code
| need to keep the current page open and to redirect the
| user to a newly opened browser window with a link like:
| http://www.mydomain.co m/tellme.aspx?cli entID="+ID
|
| But the Response.Redire ct(URL) opens a new page in the same
| window.
|
| Someone suggested to insert a JavaScript function to button's
| OnClick event. But this insertion needs to be done in Page_Load().
| And the parameter the target url needs is not available yet at
| page load time.
|
| If I insert the window.open() JavaScript in btnGo_Click() event,
| the window.open JavaScript will only be available after first click
| event.
|
| I also thought of asp:hyperlink control. It does have a target property
| and can not fire any event on server side.
|
| Would you please give some work around idea regarding what I
| want to do?
|
| Thank you
|
| hb
|
|

Nov 18 '05 #3
hb
After intensive searching online, I found a way to open a new browser window
in button click event. Instead of using Response.Redire ct(), use
Response.Write( )
to add a javascript code to the page. Here it is:
btnPack_Click(o bject sender, System.EventArg s e)
{
string orderID1=((Butt on)sender).ID;//get the button's ID
//some data processing
Response.Write( "<script
language=javasc ript>window.ope n('/pack.aspx?slipO rderID="+orderI D1

+"',
win','toolbar=0 ,location=0,dir ectories=0,stat us=1,menubar=1, scrollbars=1,re s
izable=1,"

+"width=600,hei ght=600');</script>");

}

Note: the Response.Write( ) needs to be placed at the bottom of
btnPack_Click() .
Nov 18 '05 #4

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

Similar topics

3
3141
by: Leonard | last post by:
I have a button on my web app, that opens a help html page. I use this code: HttpContext.Current.Response.Write("<script>") HttpContext.Current.Response.Write("window.open('" & sUrl & "','_new')") HttpContext.Current.Response.Write("</script>") This works ok, the html page opens in a new browser window, but when I close the help, click on a different menu item in my app, and then click the back button, the help window opens up again....
8
2523
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 click two buttons, one to save the session data and the other one to trigger the java script to open the new window. Your advice is highly appreciated. Jie
6
2727
by: Shamin | last post by:
Hi, Thanks in advance for answering to my Question. I'm stuck with this problem and would really appreciate any help. I have 2 aspx files (Main.aspx and ReportViewer.aspx). Main.aspx has a datagrid which is populated with list of report names. When the user click on the name of a report, I display a panel that has a button which on clicking will run the report. The report will open in ReportViewer.aspx, This page has a Report Document...
1
5407
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for that), the popup window will have also a text box and a button. when the User click on the button the value on the textbox will be send back to the textbox on My_WUC. I hope I was clear off what I want to do. I've been searching for some ideas...
4
2895
by: rbutch | last post by:
hey guys i've got a question as to why something is happening. basically building a web application, and i want to open up another .aspx form, but not close the one i have. so, i assign a button this. MyButton.Attributes.Add("onclick", "window.open('MyForm.aspx');") it works great but, it takes two clicks before it responds. i really do like the effect of the other .aspx file opening, leaving the main.aspx intact.
1
1752
by: Jack | last post by:
Hi, How do I open a new window in a button click event (server-side)? I need to open it from this event because once the user has click the button, the event handler does some processing and creates a query string. If I didn't need the query string it wouldn't be a problem - I would just use javascript client-side.
2
2940
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 (keeping it on top). I have most of it working but I can't get it all working. I can either have the window open and disable the buttons with the new window in the background, or I can have the new window in the foreground but not be able to disable...
6
21409
by: shil | last post by:
I have a server side button that needs to do some preperation and afterwards, if everything goes well, open a new browser with a specific url. I know how to execute javascript from a server side control, adding the javascript to the attributes. I need to open the browser window AFTER the code behind event is finished. For example I have two text boxes on the form, whose values I want to send as parameters to the URL that I want to...
5
1406
by: nashak | last post by:
Hello, I have a aspx page on which I have a button. In the click event method in code-behind I do some processing and now need to open a new window in another browser and pass a couple of parameters. I included in my aspx file, the following js function: function OpenChecklist(strCaseID) {
0
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8773
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9445
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.