10.02.2014 Views

Beginning Ajax With ASP.NET (2006).pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Other <strong>Ajax</strong> Frameworks for .<strong>NET</strong><br />

Switch to the source window to update the ComplexControls class.<br />

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

{<br />

protected void Page_Load(object sender, EventArgs e)<br />

{<br />

this.HiddenFormPostBack = true;<br />

}<br />

protected void btnLoadResources_Click(object sender, EventArgs e)<br />

{<br />

System.Data.DataSet ds;<br />

ds = new System.Data.DataSet();<br />

ds.ReadXml(Server.MapPath(“~/App_Data/Resources.xml”));<br />

}<br />

this.grdResources.DataSource = ds;<br />

this.grdResources.DataBind();<br />

}<br />

protected void grdResources_SelectedIndexChanged(object sender, EventArgs e)<br />

{<br />

this.lblSelectedIndex.Text =<br />

this.grdResources.SelectedIndex.ToString();<br />

}<br />

The page will inherit from the Comfort<strong>ASP</strong>.<strong>NET</strong> base page and will turn on the HiddenFormPostBack<br />

property in the Page_Load method. When the Load Resources button is clicked, you will load the data<br />

from the Resources.xml file and bind it to the GridView control. Finally, when an item in the grid is<br />

selected, the SelectedIndex is printed to the lblSelectedIndex label on the page.<br />

You can now launch the application in the browser to test your code.<br />

Example 3: Comfort<strong>ASP</strong>.<strong>NET</strong> Manager Control<br />

The Comfort<strong>ASP</strong>.<strong>NET</strong> Manager control gives you a centralized place to administer the page’s <strong>Ajax</strong> capabilities.<br />

The manager control provides services that implement many common requirements. We will<br />

review some of the more common features of the control here, but please refer to the Comfort<strong>ASP</strong>.<strong>NET</strong><br />

web site for full documentation of the Manager control.<br />

If you want to stop a user from repeatedly clicking on a button that initiates an <strong>Ajax</strong> call, you might<br />

choose to disable the button once the call is dispatched. Comfort<strong>ASP</strong>.<strong>NET</strong> makes it easy to disable these<br />

controls. The manager’s DisableFormWhilePostBack property will automate this process of enabling<br />

or disabling the controls on a page during a callback to the server. If the property is set to true, then all<br />

controls are disabled during an <strong>Ajax</strong> call; otherwise, the controls are left alone.<br />

<strong>Ajax</strong> applications face the challenge that the server will not always respond in a timely manner. Consider<br />

what the user would think when he or she clicks a button and nothing happens on the page for well over<br />

a minute, or perhaps never. The Comfort<strong>ASP</strong>.<strong>NET</strong> Manager control has a built-in safeguard against this<br />

situation. The HiddenRequestTimeout property will define the number of seconds the page should wait<br />

213

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

Saved successfully!

Ooh no, something went wrong!