Page 49 - DCAP312_WEB_TECHNOLOGIES_II
P. 49
Unit 3: Server Controls Basic
The page framework provides predefined HTML server controls for the HTML elements most Notes
commonly used dynamically on a page: forms, the HTML <INPUT> elements (text box, check
box, Submit button, and so on), list box (<SELECT>), table, image, and so on. These predefined
HTML server controls share the basic properties of the generic control, and in addition, each
control typically provides its own set of properties and its own event.
3.1 PostBack
PostBack is the name agreed to the procedure of submitting an ASP.NET page to the server for
dispensation. PostBack is done if definite credentials of the page are to be tartan alongside a
database (such as verification of username and password). This is something that a customer
machine is not able to accomplish and thus these fine points have to be ‘posted back’ to the
server. A simple example to illustrate the usage of PostBack is a login page. After the user has
typed his username and password, he clicks on the ‘Login’ button. Upon the click, the page
is sent to the server to check against the database/XML file to check if the user with supplied
details is an authenticated user.
Then there arise definite events in an ASP.NET page upon which a PostBack power be needed.
Consider the case in which we have 2 Combo Boxes. Let us say the first Combo Box asks us
for the Country we reside in and the second one asks us for the State/Province in that country.
Based upon the Country we select, the list of States/Provinces must be shown. Thus, in order
to fill the values in the second Combo Box, the selection in the first Combo Box must be known
to the server. Thus, as and when an item is selected in the first Combo Box, a PostBack must be
done and the appropriate list of items must be filled in the second Combo Box.
To handle these situations, we need to enable the ‘Auto PostBack’ property for those controls
whose events are going to trigger some kind of server processing.
PostBack is the name given to the process of submitting an ASP.NET page to the server for
processing. PostBack is done if certain credentials of the page are to be checked against some
sources (such as verification of username and password using database). This is something
that a client machine is not able to accomplish and thus these details have to be ‘posted back’
to the server.
3.1.1 AutoPostBack Property in ASP.NET
If we make a web Page, which consists of one or more Web Controls that are configured to use
AutoPostBack the ASP.Net adds an unusual JavaScript function to the rendered HTML Page.
This function is named _doPostBack (). When called, it triggers a PostBack, sending data back
to the web Server.
ASP.NET also adds two additional hidden input fields that are used to pass information back to
the server. This information consists of ID of the Control that raised the event and any additional
information if needed. These fields will empty initially as shown below,
<input type= “hidden” name= “__EVENTTARGET” id= “__EVENTTARGET” value= ““ />
<input type= “hidden” name= “__EVENTARGUMENT” id= “__EVENTARGUMENT” value=
““ />
The _doPostBack () function has the responsibility for setting these values with the appropriate
information about the event and the submitting the form. The _doPostBack () function is shown
below:
<script language= “text/JavaScript”>
Function __doPostBack (event Target, event Argument) {
LOVELY PROFESSIONAL UNIVERSITY 43