Button
This control is used to perform events. It is also
used to submit client request to the server. To
create Button either we can write code or use the
drag and drop facility of visual studio IDE.
The example is given below.
< asp:ButtonID="Button1" runat="server" Text="Submit"/>
This control has its own properties that are tabled below.
Example
HyperLink
It is a control that is used to create a hyperlink.
It responds to a click event. We can use it to
refer any web page on the server.
The example is given below.
< asp:HyperLinkID="HyperLink1" runat="server" Text=“IHRD" N
avigateUrl="www.ihrd.ac.in" ></asp:HyperLink>
This control has its own properties that are tabled below.
ASP.NET - Event Handling
• An event is an action or occurrence such as a mouse click, a
key press, mouse movements, or any system-generated
notification. A process communicates through events. For
example, interrupts are system-generated events. When
events occur, the application should be able to respond to it
and manage it.
• Events in ASP.NET raised at the client machine, and handled at
the server machine. For example, a user clicks a button
displayed in the browser. A Click event is raised. The browser
handles this client-side event by posting it to the server.
• The server has a subroutine describing what to do when the
event is raised; it is called the event-handler. Therefore, when
the event message is transmitted to the server, it checks
whether the Click event has an associated event handler. If it
has, the event handler is executed.
• Event Arguments
• ASP.NET event handlers generally take two
parameters and return void. The first
parameter represents the object raising the
event and the second parameter is event
argument.
• The general syntax of an event is:
private void EventName (object sender, EventArgs e);
• Application and Session Events
• The most important application events are:
• Application_Start - It is raised when the
application/website is started.
• Application_End - It is raised when the
application/website is stopped.
• Similarly, the most used Session events are:
• Session_Start - It is raised when a user first
requests a page from the application.
• Session_End - It is raised when the session
ends.
• Page and Control Events
• Common page and control events are:
• DataBinding - It is raised when a control binds to a data
source.
• Disposed - It is raised when the page or the control is
released.
• Error - It is a page event, occurs when an unhandled
exception is thrown.
• Init - It is raised when the page or the control is initialized.
• Load - It is raised when the page or a control is loaded.
• PreRender - It is raised when the page or the control is to
be rendered.
• Unload - It is raised when the page or control is unloaded
from memory.
• Event Handling Using Controls
• All ASP.NET controls are implemented as classes, and they
have events which are fired when a user performs a certain
action on them. For example, when a user clicks a button
the 'Click' event is generated. For handling events, there
are in-built attributes and event handlers. Event handler is
coded to respond to an event, and take appropriate action
on it.
• By default, Visual Studio creates an event handler by
including a Handles clause on the Sub procedure. This
clause names the control and event that the procedure
handles.
• The ASP tag for a button control:
• <asp:Button ID="btnCancel" runat="server" Text="Cancel"
/>The event handler for the Click event:
• Protected Sub btnCancel_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btnCancel.Click End
Sub
• Some events cause the form to be posted back to
the server immediately, these are called the
postback events. For example, the click event
such as, Button.Click.
• Some events are not posted back to the server
immediately, these are called non-postback
events.
• For example, the change events or selection
events such as TextBox.TextChanged or
CheckBox.CheckedChanged. The nonpostback
events could be made to post back immediately
by setting their AutoPostBack property to true.
• Default Events
• The default event for the Page object is Load
event. Similarly, every control has a default
event. For example, default event for the
button control is the Click event.
• The default event handler could be created in
Visual Studio, just by double clicking the
control in design view. The following table
shows some of the default events for common
controls:
RadioButton
It is an input control which is used to takes
input from the user. It allows user to select a
choice from the group of choices.
The example is given below.
< asp:RadioButtonID="RadioButton1" runat="server" Text="Male
" GroupName="gender"/>
Calendar
It is used to display selectable date in a
calendar. It also shows data associated with
specific date. This control displays a calendar
through which users can move to any day in
any year.
< asp:CalendarID="Calendar1" runat="server“></asp:Calendar>
LinkButton
It is a server web control that acts as a hyperlink. It is used to display a
hyperlink-style button control on the web page.
Listbox
The ASP.NET Core ListBox is a graphical user interface for displaying a list
of items with multi-selection options. It has a rich appearance and allows
users to select one or more items from the list using checkboxes or
keyboard interactions.
Checkbox
• It is used to get multiple inputs from the user. It allows user to
select choices from the set of choices.
• It takes user input in yes or no format. It is useful when we
want multiple choices from the user.
DropDownList
The DropDownList is a web server control which is used to
create an HTML Select component. It allows us to select an
option from the dropdown list. It can contain any number of
items.user can select only one option at a time that means
select a single item from a list of items.
Radiobutton list