By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

How to open a new window in button click event?

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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****@goodoffices.com> wrote in message
news:uV**************@TK2MSFTNGP09.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.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
|
|
Nov 18 '05 #2

P: n/a
hb
I see. Thank you.

hb
"bruce barker" <no***********@safeco.com> wrote in message
news:uc**************@TK2MSFTNGP14.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****@goodoffices.com> wrote in message
news:uV**************@TK2MSFTNGP09.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.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
|
|

Nov 18 '05 #3

P: n/a
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().
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.