10.02.2014 Views

Beginning Ajax With ASP.NET (2006).pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9<br />

Try It Out<br />

Using PanelUpdater Control<br />

Begin by adding a new web form to the solution, naming it PanelUpdater.aspx. Make sure that you are<br />

in source view, and add the following line after the Page directive line found at the top of the <strong>ASP</strong>X page.<br />

<br />

The Register tag will make the Comfort<strong>ASP</strong>.<strong>NET</strong> framework available to the page.<br />

Continue by adding the following markup between the tags:<br />

<br />

<br />

Message Count:<br />

<br />

<br />

The <strong>ASP</strong>.<strong>NET</strong> panel is the container for the section of the page to update. The Comfort<strong>ASP</strong>.<strong>NET</strong><br />

PanelUpdater control will handle generating the client-side code to create the timeout behavior. Be sure<br />

to activate the PanelUpdater by setting the Active property equal to true. The TimerIntervalUpdate<br />

property will take a value for the number of seconds you want the browser to wait before contacting the<br />

server. Finally, the label at the end of the listing will take the latest information from the server and print<br />

the message count back to the user.<br />

Now switch to the code window to update the PanelUpdater class.<br />

public partial class PanelUpdater : Comfort<strong>ASP</strong>.Comfort<strong>ASP</strong>_Page<br />

{<br />

private int MessageCount<br />

{<br />

get<br />

{<br />

if (this.ViewState[“messageCount”] == null)<br />

{<br />

return 0;<br />

}<br />

else<br />

{<br />

return Convert.ToInt32(this.ViewState[“messageCount”]);<br />

}<br />

}<br />

set<br />

{<br />

this.ViewState.Add(“messageCount”, value);<br />

218

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!