How to open a new window in the server side?

J

J Gao

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
 
K

Kevin Spencer

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.
 
S

S. Justin Gengo

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

J Gao

It does not work because it cannot guarantee that which event occurs first.
I am trying to use S. Justin Gengo's suggestion. Thanks
 
J

J Gao

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

S. Justin Gengo

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
 
S

S. Justin Gengo

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

J Gao

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
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top