Making Particular Control as a Trigger by
Suppressing other Child Controls of UpdatePanel control
There is a property in UpdatePanel
control called ChildrenAsTriggers which accepts Boolean to enable/disable
the child controls as its triggers. We can make this property to false and
specify the child control as an AsyncPostBackTrigger.
//Child controls go here
<asp:AsyncPostBackTrigger ControlID="Button1" />
To have this working, we need to make
the UpdateMode property to Conditional. Setting UpdateMode property to Always
will give the following error.
ChildrenAsTriggers cannot be set to
false when UpdateMode is set to Always on UpdatePanel
Refreshing whole page through a child
control of UpdatePanel
In previous sections, we used
AsyncPostBackTrigger to set a new trigger to UpdatePanels. As the name suggests,
the AsyncPostBackTrigger is used to refresh the UpdatePanel asynchronously. At
times, we will have requirements to refresh the page fully instead of
partially/asynchronously. To do this, we have another trigger to UpdatePanel
controls called PostbackTrigger.
When we are adding a control as a
Trigger to UpdatePanel, we will get an option for adding a new trigger as
//Child controls go here
In the above code, Button1 will
generate postback that refreshes the whole page.
You can have a control as an
Asynchronous trigger to one UpdatePanel and PostBack trigger to another
UpdatePanel simultaneously. It will throw the following error!
Control with ID 'btnOut' cannot be
registered through both RegisterAsyncPostBackControl and
RegisterPostBackControl. This can happen if you have conflicting triggers
associated with the target control.
Initiating Postback on UpdatePanel
control at Regular Intervals
Whenever we need to refresh our page in
asp.net we use meta tags. ASP.Net 2.0 introduced a new class called HtmlMeta
that helps in using this functionality in codebehind. ASP.Net AJAX equivalent is
to refresh UpdatePanel control instead of whole page.
To achieve this, there is a control called Timer control
with ASP.Net AJAX which helps us to refresh the UpdatePanel after the specified
times in milliseconds contained in Interval property.
ID="Button1" runat="server" OnClick="Button1_Click" Text="Button"
ID="Button2" runat="server" OnClick="Button2_Click" Text="Button"
runat="server" Interval="1000" OnTick="Timer1_Tick">
ControlID="Timer1" EventName="Tick" />
protected void Timer1_Tick(object sender,
Server Validations with ASP.Net
As we all know, not all validations can
be done on client side. Some of the validations should be done in serverside and
these validations are done based on some data or business rules on server side.
For example, we have enabled “Vendor Name” only for temporary employee in
previous example. Suppose, if we want to throw an error message when the user
enters a vendor name who are not in our vendor list then we can include a
CustomValidator with a server side validation function.
ID="CustomValidator1" ControlToValidate="txtVendor" runat="server"
ErrorMessage="Vendor Not in List"
protected void Page_Load(object sender,
CustomValidator1_ServerValidate(object source, ServerValidateEventArgs
string vendors =
int index = Array.IndexOf(vendors,
if (index == -1)
When executed, the validation function
will be called when the user types in a vendor name and tabs out because we have
specified AutoPostBack="true" for the textbox. This gives an impression
that the validation is client side like other validations. Refer the below