ASP.NET Question

G

Guest

How do I make PostBack Call from the Server so that I can update something on the client web browser? The Client just has the page open theres is no event from the Client. But I want to push something from the server so that the client webpage reloads with the new information. Code Sample Please

Shreyash
 
C

Curt_C [MVP]

nope....
http is Request/Response... not push based.


--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com


Shreyash Patel said:
How do I make PostBack Call from the Server so that I can update something
on the client web browser? The Client just has the page open theres is no
event from the Client. But I want to push something from the server so that
the client webpage reloads with the new information. Code Sample Please?
 
G

Guest

Then ASP.NET Chat would never be possible. The ASP.NET for Dummies has a implementation of a Chat Room Applicaiton created just using ASP.NET. There must be some way of forcing the client page to refresh or update.
 
J

Jeffrey A. Voigt

We have something similar on our site. check out
www.myfloridahouse.com/session_live_preview.aspx. We have to update
information to the user every 60 seconds so the user knows if the House is
dicussing another bill and/or amendment. We achived this by setting an
autopost back every 60 seconds with the following code:

private void RegisterRefreshScript()
{
// register a script to auto post back every so many seconds
// NOTE: Setting a meta tag to refresh will not do a (POST BACK)
int refreshRate =
Convert.ToInt32(ConfigurationSettings.AppSettings["SessionLiveRefreshRate"])
;
StringBuilder scriptBlock = new StringBuilder();
scriptBlock.Append( "<script>" );
scriptBlock.Append( "function sessionLive_autoPostBack() ");
scriptBlock.Append( "{ " );
scriptBlock.Append( " __doPostBack('lnkPostBack','');");
scriptBlock.Append( "} " );
scriptBlock.Append( "window.setInterval( 'sessionLive_autoPostBack()', ");
scriptBlock.Append( refreshRate.ToString() );
scriptBlock.Append( "); ");
scriptBlock.Append( "</script>" );
RegisterStartupScript( "autoPostBack", scriptBlock.ToString() );
}

If you call this function each time there is a postback, you can be assurred
that the brower will post back to the server every so many seconds. Don't
let this confuse you, the lnkPostBack is just a server side link button
declare on the ASPX page like so:

<asp:LinkButton ID="lnkPostBack" Runat="server"></asp:LinkButton>

What is nice is that that when the post back happens it will call the
lnkPostBack_Click event (so long as you have an event for it set up) so you
know the difference between the user clicking the refresh button, other
buttons that may cause a post back, and the registered script block that was
added.

Let me know if this helps you out!

Thanks,


Shreyash Patel said:
How do I make PostBack Call from the Server so that I can update something
on the client web browser? The Client just has the page open theres is no
event from the Client. But I want to push something from the server so that
the client webpage reloads with the new information. Code Sample Please?
 
B

Brian H

Not really. One way to implement this would be to use either a hidden
frame, or have a page auto-refresh at a given interval (say 10 seconds).
Using session variables (for example) you can track what messages the client
has already seen, and send any news ones.

But you can't do this server side; the key to pulling this off would be to
use some "hack" client side to post/get back.

Brian


Shreyash Patel said:
Then ASP.NET Chat would never be possible. The ASP.NET for Dummies has a
implementation of a Chat Room Applicaiton created just using ASP.NET. There
must be some way of forcing the client page to refresh or update.
 
C

Curt_C [MVP]

yes, you can force the client to refresh, that's not what you asked though.
you can use a simple meta refresh tag for this even. You asked to have the
SERVER push without a client request.....that's not currently possible
without a component

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com


Shreyash Patel said:
Then ASP.NET Chat would never be possible. The ASP.NET for Dummies has a
implementation of a Chat Room Applicaiton created just using ASP.NET. There
must be some way of forcing the client page to refresh or update.
 
P

pitcher17

That's great. I can follow everything that you're doing here except for the
line
"RegisterStatupScript("autoPostBack", scriptBlock.ToString() );"

What is this doing? Is this a function name of yours or something that has
special meaning in ASP.Net?

Pitcher



Jeffrey A. Voigt said:
We have something similar on our site. check out
www.myfloridahouse.com/session_live_preview.aspx. We have to update
information to the user every 60 seconds so the user knows if the House is
dicussing another bill and/or amendment. We achived this by setting an
autopost back every 60 seconds with the following code:

private void RegisterRefreshScript()
{
// register a script to auto post back every so many seconds
// NOTE: Setting a meta tag to refresh will not do a (POST BACK)
int refreshRate =
Convert.ToInt32(ConfigurationSettings.AppSettings["SessionLiveRefreshRate"])
;
StringBuilder scriptBlock = new StringBuilder();
scriptBlock.Append( "<script>" );
scriptBlock.Append( "function sessionLive_autoPostBack() ");
scriptBlock.Append( "{ " );
scriptBlock.Append( " __doPostBack('lnkPostBack','');");
scriptBlock.Append( "} " );
scriptBlock.Append( "window.setInterval( 'sessionLive_autoPostBack()', ");
scriptBlock.Append( refreshRate.ToString() );
scriptBlock.Append( "); ");
scriptBlock.Append( "</script>" );
RegisterStartupScript( "autoPostBack", scriptBlock.ToString() );
}

If you call this function each time there is a postback, you can be assurred
that the brower will post back to the server every so many seconds. Don't
let this confuse you, the lnkPostBack is just a server side link button
declare on the ASPX page like so:

<asp:LinkButton ID="lnkPostBack" Runat="server"></asp:LinkButton>

What is nice is that that when the post back happens it will call the
lnkPostBack_Click event (so long as you have an event for it set up) so you
know the difference between the user clicking the refresh button, other
buttons that may cause a post back, and the registered script block that was
added.

Let me know if this helps you out!

Thanks,


Shreyash Patel said:
How do I make PostBack Call from the Server so that I can update
something
on the client web browser? The Client just has the page open theres is no
event from the Client. But I want to push something from the server so that
the client webpage reloads with the new information. Code Sample Please?
 
J

Jeffrey A. Voigt

RegisterStartupScript is an ASP.NET function that will add and execute the
script as soon as the client receives the web page. The first param is just
a name you can give the script block. I just chose to use "autoPostBack"
for the name. The second param is the actual script. That was constructed
in the above lines.

Thanks,
- jv

pitcher17 said:
That's great. I can follow everything that you're doing here except for the
line
"RegisterStatupScript("autoPostBack", scriptBlock.ToString() );"

What is this doing? Is this a function name of yours or something that has
special meaning in ASP.Net?

Pitcher



Jeffrey A. Voigt said:
We have something similar on our site. check out
www.myfloridahouse.com/session_live_preview.aspx. We have to update
information to the user every 60 seconds so the user knows if the House is
dicussing another bill and/or amendment. We achived this by setting an
autopost back every 60 seconds with the following code:

private void RegisterRefreshScript()
{
// register a script to auto post back every so many seconds
// NOTE: Setting a meta tag to refresh will not do a (POST BACK)
int refreshRate =
Convert.ToInt32(ConfigurationSettings.AppSettings["SessionLiveRefreshRate"])
;
StringBuilder scriptBlock = new StringBuilder();
scriptBlock.Append( "<script>" );
scriptBlock.Append( "function sessionLive_autoPostBack() ");
scriptBlock.Append( "{ " );
scriptBlock.Append( " __doPostBack('lnkPostBack','');");
scriptBlock.Append( "} " );
scriptBlock.Append( "window.setInterval( 'sessionLive_autoPostBack()', ");
scriptBlock.Append( refreshRate.ToString() );
scriptBlock.Append( "); ");
scriptBlock.Append( "</script>" );
RegisterStartupScript( "autoPostBack", scriptBlock.ToString() );
}

If you call this function each time there is a postback, you can be assurred
that the brower will post back to the server every so many seconds. Don't
let this confuse you, the lnkPostBack is just a server side link button
declare on the ASPX page like so:

<asp:LinkButton ID="lnkPostBack" Runat="server"></asp:LinkButton>

What is nice is that that when the post back happens it will call the
lnkPostBack_Click event (so long as you have an event for it set up) so you
know the difference between the user clicking the refresh button, other
buttons that may cause a post back, and the registered script block that was
added.

Let me know if this helps you out!

Thanks,


something
on the client web browser? The Client just has the page open theres is no
event from the Client. But I want to push something from the server so that
the client webpage reloads with the new information. Code Sample Please?
 
P

pitcher17

Ok. So, "autoPostBack" is just the name you gave it in order to reference
it later?

thank you.

Jeffrey A. Voigt said:
RegisterStartupScript is an ASP.NET function that will add and execute the
script as soon as the client receives the web page. The first param is just
a name you can give the script block. I just chose to use "autoPostBack"
for the name. The second param is the actual script. That was constructed
in the above lines.

Thanks,
- jv

pitcher17 said:
That's great. I can follow everything that you're doing here except for the
line
"RegisterStatupScript("autoPostBack", scriptBlock.ToString() );"

What is this doing? Is this a function name of yours or something that has
special meaning in ASP.Net?

Pitcher
House
Convert.ToInt32(ConfigurationSettings.AppSettings["SessionLiveRefreshRate"])
'sessionLive_autoPostBack()',
"); so
you that
was
 
J

Jeffrey A. Voigt

"autoPostBack" is just a name given to the script... you can put in
"blahblahblah" and it would not make a difference. It is not referenced
anywhere, it is just to give meaning to the script block, that's about it :)

Thanks,
- jv

pitcher17 said:
Ok. So, "autoPostBack" is just the name you gave it in order to reference
it later?

thank you.

Jeffrey A. Voigt said:
RegisterStartupScript is an ASP.NET function that will add and execute the
script as soon as the client receives the web page. The first param is just
a name you can give the script block. I just chose to use "autoPostBack"
for the name. The second param is the actual script. That was constructed
in the above lines.

Thanks,
- jv

for
the that
has House
Convert.ToInt32(ConfigurationSettings.AppSettings["SessionLiveRefreshRate"])
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top