How to open a new window in button click event?

H

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.com/tellme.aspx?clientID="+ID

But the Response.Redirect(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
 
B

bruce barker

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)


| 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.com/tellme.aspx?clientID="+ID
|
| But the Response.Redirect(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
|
|
 
H

hb

After intensive searching online, I found a way to open a new browser window
in button click event. Instead of using Response.Redirect(), use
Response.Write()
to add a javascript code to the page. Here it is:
btnPack_Click(object sender, System.EventArgs e)
{
string orderID1=((Button)sender).ID;//get the button's ID
//some data processing
Response.Write("<script
language=javascript>window.open('/pack.aspx?slipOrderID="+orderID1

+"',
win','toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,res
izable=1,"

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

}

Note: the Response.Write() needs to be placed at the bottom of
btnPack_Click().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top