Книга: C# 2008 Programmer

Using Triggers to Cause an Update

Using Triggers to Cause an Update

So far, you have used the <asp:UpdatePanel> control to enclose controls to ensure that changes in this control do not cause a postback to the server. If you select a publisher from the dropdown list, though, you will realize that the entire page is refreshed. By adding a trigger to the page, you can specify a control (and, optionally, its event) that causes an <asp:UpdatePanel> control to refresh. The trigger <asp:AsyncPostBackTrigger> causes an update when the specified control raises an event. In other words, when a control specified by a trigger causes an update to a control located with an <asp:UpdatePanel> control, only the control is updated and not the entire page.

Here's the markup you need to add a trigger to an <asp:UpdatePanel> control:

<asp:UpdatePanel runat="server">
  <asp:AsyncPostBackTrigger ControlID="DropDownList1"/>

Here, the <asp:UpdatePanel> control will refresh whenever the value of DropDownList1 changes.

Press F5 to test the application. Now selecting a publisher from the dropdown list updates the GridView control without causing a refresh in the page.

Оглавление книги

Генерация: 1.126. Запросов К БД/Cache: 3 / 0
Вверх Вниз