Call server side code from client side

B

Borr

Hi,

I have an ASP .NET page, that runs client side timer that
does something on the Server side and after that loads
another page. So I have on client side something like :

function OnPageLoad()
{
setTimeout("OnTimer()", 10000);
}

function OnTimer()
{
ServerMethod();
}

<body onload="OnPageLoad()">
<form id="Form1" method="post" runat="server">

It does not work, and I understand why - client side does
not know what is ServerMethod();

How to call server side method from the timer callback ?
Meanwhile I found workaround : created in Form1 tiny
disabled button DummyBtn "runat=server", defined such
server-side event handler for click :

void DummyBtn_ServerClick(object obj,EventArgs e)
{
ServerMethod();
}

and on the client side in OnTimer method wrote

Form1.DummyBtn.click();

So the timer simulates click of DummyBtn, click runs its
event handler, the event handler in turn calls the server
method.

It works, but it is ugly solution. I 'd like to call
ServerMethod() from the timer callback directly, without
tricks like this. Is it possible ?
 
J

Jj

there is no direct live connection between the client side and server side,
because HTTP is a stateless connetion type.

Unlesss you use something like ActiveX, or Java applet, the only way you can
communicate between the client and server sides are doing the form posting.

Alone this line, you can call form.submit() method in your timer method and
activate the server side methods.

Jianjun
 
A

Alvin Bruney

That's not entirely true, you can use server side blocks to execute methods
on the server-side although it is a somewhat advanced technique.
 

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,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top