Triggering both client and server side scripts

K

Karim

I have a button that opens a new Window using client side Javascript. The
button also has server side script (.._click) that saves some session
variables to be used in the new Window.

The problem is that the server side function does not fire.

Karim
 
K

Ken Cox [Microsoft MVP]

Hi Karim,

Here's some code that might work for you. Not sure whether the setting of
the Session variable will be done in time for the secondary window to fetch.
Depends on the speed of the server, I suppose.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Attributes.Add _
("onclick", "window.open('sec.aspx','sec');return true;")
End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Session("stored") = "here is the value at " & _
Now.ToLongTimeString
End Sub
 
K

Karim

Hi Karim,

Here's some code that might work for you. Not sure whether the setting of
the Session variable will be done in time for the secondary window to fetch.
Depends on the speed of the server, I suppose.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Attributes.Add _
("onclick", "window.open('sec.aspx','sec');return true;")
End Sub

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Session("stored") = "here is the value at " & _
Now.ToLongTimeString
End Sub


Thanks. Your code resembles what I have. The problem is that the button
click doesn't fire. I want to execute code in the click event first to set
the session variables, then open window fires up to open a new window whose
page_load event reads in the session variables that were set by the
parent's window. I guess I will have to send the parameters through a
querystring which will will built dynamically in the open window script.
The variables are some form fields.

Does anyone have a better way of doing this?

Karim
 
K

Karim

Thanks. Your code resembles what I have. The problem is that the button
click doesn't fire. I want to execute code in the click event first to set
the session variables, then open window fires up to open a new window whose
page_load event reads in the session variables that were set by the
parent's window. I guess I will have to send the parameters through a
querystring which will will built dynamically in the open window script.
The variables are some form fields.

Does anyone have a better way of doing this?

Karim

Well now after many tries I found that the click does fire sometimes. It
sometimes gets fired before the new Window is opened, sometimes gets fired
after the new Window is opened and sometimes the click event never fires.
This is very inconsistent!

Karim
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top