468,268 Members | 2,002 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

How to open a new window in the server side?

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
Nov 17 '05 #1
8 2346
In your button click Event Handler, add the data to the Session. Then add a
JavaScript to the Page using RegisterStartupScript() to open a window
containing the second page. The second Page can then grab the Session data.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
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

Nov 17 '05 #2
J Gao,

I would use the body tag as a server control. Your page would be posted back
by the button click as normal, the session would be saved, and then you
would add javascript to open your window to the body tag's attribute
collection's onload event. This way the window will open as soon as the page
is reloaded on the client.

I have example code for how to do this on my web site,
www.aboutfortunate.com, in the code library. Search for "use body tag as
server control".

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
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

Nov 17 '05 #3
It does not work because it cannot guarantee that which event occurs first.
I am trying to use S. Justin Gengo's suggestion. Thanks
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
In your button click Event Handler, add the data to the Session. Then add a JavaScript to the Page using RegisterStartupScript() to open a window
containing the second page. The second Page can then grab the Session data.
--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
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


Nov 17 '05 #4
Thanks.
But even if I add
<body id="body" runat="server">, I cannot see the body object. Can you tell
me where to add:
Body.Attributes.Add("onLoad", "javascript:alert('The username or password
entered was not valid.');")

"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
J Gao,

I would use the body tag as a server control. Your page would be posted back by the button click as normal, the session would be saved, and then you
would add javascript to open your window to the body tag's attribute
collection's onload event. This way the window will open as soon as the page is reloaded on the client.

I have example code for how to do this on my web site,
www.aboutfortunate.com, in the code library. Search for "use body tag as
server control".

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
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


Nov 17 '05 #5
J Gao,

In your code behind page you must also declare the new body tag. Did you
look at the sample?

'---First in the html view of your web form make the body tag into a server
control.
' To do so, give it an id and a runat="server" attribute.
<body id="body" runat="server">
******************************
****Here's the part you're missing.****
******************************

'---Next declare the body object in your code behind page.
Protected Body As System.Web.UI.HtmlControls.HtmlGenericControl

'---Now when you want to pop up a javascript alert
' just add it to the body tag.
Body.Attributes.Add("onLoad", "javascript:alert('The username or password
entered was not valid.');")
Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:eH**************@TK2MSFTNGP10.phx.gbl...
Thanks.
But even if I add
<body id="body" runat="server">, I cannot see the body object. Can you tell me where to add:
Body.Attributes.Add("onLoad", "javascript:alert('The username or password
entered was not valid.');")

"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
J Gao,

I would use the body tag as a server control. Your page would be posted

back
by the button click as normal, the session would be saved, and then you
would add javascript to open your window to the body tag's attribute
collection's onload event. This way the window will open as soon as the

page
is reloaded on the client.

I have example code for how to do this on my web site,
www.aboutfortunate.com, in the code library. Search for "use body tag as
server control".

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
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



Nov 17 '05 #6
Thanks Gengo. I forgot to define the body in the code behind page.

"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
J Gao,

I would use the body tag as a server control. Your page would be posted back by the button click as normal, the session would be saved, and then you
would add javascript to open your window to the body tag's attribute
collection's onload event. This way the window will open as soon as the page is reloaded on the client.

I have example code for how to do this on my web site,
www.aboutfortunate.com, in the code library. Search for "use body tag as
server control".

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
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


Nov 17 '05 #7
Great!

I'm glad it worked for you. I re-read my post after your question about what
you were missing and I thought my question "Did you look at the sample?"
might have sounded a little strong. If it did I apologize.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Great. It works. Thanks.

jie

"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
J Gao,

I would use the body tag as a server control. Your page would be posted

back
by the button click as normal, the session would be saved, and then you
would add javascript to open your window to the body tag's attribute
collection's onload event. This way the window will open as soon as the

page
is reloaded on the client.

I have example code for how to do this on my web site,
www.aboutfortunate.com, in the code library. Search for "use body tag as
server control".

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
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



Nov 17 '05 #8
Hi, Kevin,
I am sorry I missed the RegisterStartupScript method you suggest. But can
you show me the sample codes that I can register the script and trigger it
right away? I would also like to try it. Thank

Jie
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
In your button click Event Handler, add the data to the Session. Then add a JavaScript to the Page using RegisterStartupScript() to open a window
containing the second page. The second Page can then grab the Session data.
--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

"J Gao" <ji*****@tequilasoftware.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
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


Nov 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Grey | last post: by
6 posts views Thread by Charlie Garrett-Jones | last post: by
4 posts views Thread by Guy Cohen | last post: by
2 posts views Thread by H. Rodriguez | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.