469,649 Members | 1,637 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

Call server side code from client side

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 ?

Nov 17 '05 #1
3 6758
You can use the web service behavior for this. (WebService.htc)
This technique works with IE only.
Here's more details:
http://msdn.microsoft.com/library/de...s/overview.asp

http://msdn.microsoft.com/downloads/...ce/default.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"Borr" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
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 ?

Nov 17 '05 #2
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
"Borr" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
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 ?

Nov 17 '05 #3
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.

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Jj" <ji*******@yahoo.com> wrote in message
news:q9********************@comcast.com...
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
"Borr" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
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 ?


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by HarveyB | last post: by
4 posts views Thread by Bonato Pierantonio | last post: by
4 posts views Thread by abcd | last post: by
11 posts views Thread by rgintexas | last post: by
reply views Thread by Werner Willemsens | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.