fire server side event from client side code

G

Guest

Hi

I have a number of HTML tables that are dynamically rendered from server side code. I've added an onClick event to the tables that fires a client side function (jscript) to redirect the user to an appropriate page using location.href

I need to capture this event some how on the server side so I can set a session variable to track the table onclick event that was raised

Does any one know how I can do this. I don't think I can set the session variable using jscript right? I'm guessing I need to hook up an event handler on the server side for the onClick event but I don't know how to do this

Thanks
 
F

Felbrigg

It seems to me that your trying to do this the hard way! Can you not add
Server controls to your dynamicly created HTML?


Neil said:
Hi,

I have a number of HTML tables that are dynamically rendered from server
side code. I've added an onClick event to the tables that fires a client
side function (jscript) to redirect the user to an appropriate page using
location.href.
I need to capture this event some how on the server side so I can set a
session variable to track the table onclick event that was raised.
Does any one know how I can do this. I don't think I can set the session
variable using jscript right? I'm guessing I need to hook up an event
handler on the server side for the onClick event but I don't know how to do
this.
 
W

www.eztree-msdn.com \( Laurent Jordi \)

Hi,

It's very simple...

First you add a hidden button (run at server on your page)
In the server side event of this control you code a response.redirect to go
to the right page...

On the onclick event of your table you call the autogenerated client code of
your event button...

I think it works...

Regards

LJ

www.eztree-msdn.com


Neil said:
Hi,

I have a number of HTML tables that are dynamically rendered from server
side code. I've added an onClick event to the tables that fires a client
side function (jscript) to redirect the user to an appropriate page using
location.href.
I need to capture this event some how on the server side so I can set a
session variable to track the table onclick event that was raised.
Does any one know how I can do this. I don't think I can set the session
variable using jscript right? I'm guessing I need to hook up an event
handler on the server side for the onClick event but I don't know how to do
this.
 
G

Guest

Hi,

Thanks for the reply but i'm not sure it solves my problem or maybe it does and I just don't understand.

Can you clarify what you mean by "call the autogenerated client code of the event button"...

I was hoping that the onClick event of the table would be able to fire some server side code. I thought I might be able to set the runat=server attribute and somehow this would or could allow me to hook up a server side handler for the onClick event as well as
a client side one.

for example

<table onClick="Runfunction()" runat=server ><tr><td>Click me</td></tr></table>

Now in my javascript section I have a function called RunFunction() and also one in my code behind page and get both to run. I understand that this should be possible and the client code would always run first if present...
 
R

Ravichandran J.V.

W

www.eztree-msdn.com \( Laurent Jordi \)

Hi again...

When you create a web control with the runat=server it means that when the
user fire the event the page must "tell" the server "My user do that". Then
The server look if there is some code in this event.

For a button, it's usually a simple submit button. If you do not specify
action and target properties, default values submit the form to itself.

The framework generate a very big hidden field that contain the original
state of controls. Before the submit, this hidden (__viewstate) is modified
by a small autogenerated client code and it's submitted to the page. The
server is now able to execute the right code...

So you can create a jscript source code that generate a submit

<TABLE ID=myTable onClick="javascript: return myTable_onclick();">

<INPUT TYPE=hidden ID=hidTransfert runat=server>

function return myTable_onclick() {
window.document.form1.hidTransfert.value = valueToTransfert;
window.document.form1.submit();
}

on the server

page_onLoad

If not ispostback then
Dim MytransferedValue = hidTransfert.value
end if

Is it more clear ?

@+

LJ

www.eztree-msdn.com
 

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

Top