How to open a new window in the server side?

  • Thread starter Thread starter J Gao
  • Start date Start date
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
 
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,

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
 
It does not work because it cannot guarantee that which event occurs first.
I am trying to use S. Justin Gengo's suggestion. Thanks
 
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.');")
 
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
 
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
 
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
 
Back
Top