C#.Net_Module-4_5
C#.Net_Module-4_5
MODULE – 4
Graphical User Interface and Windows Form
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 2
Example:
using System;
using System.Text;
using System.Windows.Forms;
namespace WFormsDemo{
// Form that shows a simple event handler
public partial class SimpleEventExample : Form {
public SimpleEventExample () {
InitializeComponent();
}
// handles click event of Button button1
private void button1_Click(object sender, EventArgs e){
MessageBox.Show("Button was Clicked");
}
}
}
using System;
using System.Windows.Forms;
namespace LinkLabelTest{
public partial class LinkLabelTestForm : Form{
public LinkLabelTestForm(){
InitializeComponent();
}
private void cDriveLinkLabel_LinkClicked( object sender,
LinkLabelLinkClickedEventArgs e) {
driveLinkLabel.LinkVisited = true;
System.Diagnostics.Process.Start( @"C:\" );
}
private void displaylabel_Click(object sender, EventArgs e){
// display the text that the user typed
displayPasswordLabel.Text = inputTextBox.Text;
}
}
}
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 4
Form properties,
Description
methods & an event
AcceptButton Button that is clicked when Enter is pressed.
AutoScroll bool value that allows or disallows scrollbars when needed.
Properties
Closes a Form and releases all resources, such as the memory used for
Close
Methods
Load is displayed in the Visual Studio editor when you double click the Form
in the Visual Studio designer.
The user can select a date from the currently displayed month or can use the provided arrows to navigate
to another month. When a date is selected, it is highlighted.
Multiple dates can be selected by clicking dates on the calendar while holding down the Shift key.
The default event for this control is the DateChanged event, which is generated when a new date is
selected.
Properties are provided that allow you to modify the appearance of the calendar, how many dates can be
selected at once, and the minimum date and maximum date that may be selected.
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 5
MonthCalendar properties and a common MonthCalendar event are summarized in below table.
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 6
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 7
After set the anchor property to Bottom, Right, now execute the application and shown as below:
Docking attaches a control to a container such that the control stretches across an entire side or fills
an entire area.
Docking allows a control to span an entire side (left, right, top or bottom) of its parent
container or to fill the entire container.
When the parent control is resized, the docked control resizes as well.
When the Form is resized, the Button is resized to the Form’s new width.
Forms have a Padding property that specifies the distance between the docked controls and
the Form edges. This property specifies four values (one for each side),and each value is set
to 0 by default.
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 8
The following figures shows how to create and set the tooltips controls:
i. We named the ToolTip component labelsToolTip.
ii. We set the tool tip text for the first Label to "First Label" and the tool tip text for the second Label to
"Second Label”.
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 9
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 10
We can change the Display mode to Year and Decade generates by setting the property DisplayModes.
Year Decades
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 11
Module – 5
Web App Development and DataAccess using ADO.NET
i. Information Tier:
The information tier also called the bottom tier.
It maintains the application’s data.
This tier typically stores data in a relational
database management system.
Example: A retail store might have a database for
storing product information, such as descriptions,
prices and quantities in stock.
The same database also might contain customer
information, such as user names, billing addresses
and credit card numbers.
This tier can contain multiple databases, which
together comprise the data needed for an
application.
Example: A business rule in the middle tier of a retail store’s web-based application might ensure that all
product quantities remain positive.
A client request to set a negative quantity in the bottom tier’s product information database would be rejected
by the middle tier’s business logic.
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 13
RequiredFieldValidator Control:
The RequiredFieldValidator control ensures that the required field is not empty. It is generally tied to a text box
to force input into the text box.
Syntax: <asp:RequiredFieldValidator ID="rfvcandidate"
runat="server" ControlToValidate ="ddlcandidate"
ErrorMessage="Please choose a candidate"
InitialValue="Please choose a candidate">
</asp:RequiredFieldValidator>
RangeValidator Control:
The RangeValidator control verifies that the input value falls within a predetermined range.
It has three specific properties:
Properties Description
It defines the type of the data. The available values are: Currency, Date,
Type
Double, Integer, and String.
MinimumValue It specifies the minimum value of the range.
MaximumValue It specifies the maximum value of the range.
CompareValidator Control:
The CompareValidator control compares a value in one control with a fixed value or a value in another control.
It has the following specific properties:
Properties Description
Type It specifies the data type.
ControlToCompare It specifies the value of the input control to compare with.
ValueToCompare It specifies the constant value to compare with.
It specifies the comparison operator, the available values are: Equal,
Operator NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual,
and DataTypeCheck.
Syntax:
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="CompareValidator">
</asp:CompareValidator>
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 14
RegularExpressionValidator:
The RegularExpressionValidator allows validating the input text by matching against a pattern of a regular
expression. The regular expression is set in the ValidationExpression property.
The following table summarizes the commonly used syntax constructs for
Regular expressions: \b, \n, \,\f, \r, \v, \t
Metacharacters: ., [abcd], [^abcd], [a-zA-Z], \w, \W, \s, \S, \d, \D
Quantifiers: *, +, ?, {n}, {n, }, {n,m}
Syntax:
<asp:RegularExpressionValidator ID="string" runat="server"
ErrorMessage="string" ValidationExpression="string"
ValidationGroup="string">
</asp:RegularExpressionValidator>
CustomValidator:
The CustomValidator control allows writing application specific custom validation routines for both the client
side and the server side validation.
The client side validation is accomplished through the ClientValidationFunction property. The client
side validation routine should be written in a scripting language, such as JavaScript or VBScript, which
the browser can understand.
The server side validation routine must be called from the control's ServerValidate eventhandler. The
server side validation routine should be written in any .Net language, like C# or VB.Net.
Syntax:
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction=.cvf_func.
ErrorMessage="CustomValidator">
</asp:CustomValidator>
ValidationSummary:
The ValidationSummary control does not perform any validation but shows a summary of all errors in the page.
The summary displays the values of the ErrorMessage property of all validation controls that failed validation.
The following two mutually inclusive properties list out the error message:
ShowSummary : shows the error messages in specified format.
ShowMessageBox : shows the error messages in a separate window.
Syntax:
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
DisplayMode = "BulletList" ShowSummary = "true"
HeaderText="Errors:" />
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 15
Validation Groups:
Complex pages have different groups of information provided in different panels. In such situation, a need might
arise for performing validation separately for separate group. This kind of situation is handled using validation
groups.
To create a validation group, you should put the input controls and the validation controls into the same logical
group by setting their ValidationGroup property.
Session Property:
Every Web Form includes a user-specific HttpSessionState object, which is accessible through property Session
of class Page. We use this property to manipulate the current user’s HttpSessionState object.
When a page is first requested, a unique HttpSessionState object is created by ASP.NET and assigned to the
Page’s Session property.
The session object is created from the HttpSessionState class, which defines a collection of session state items.
Properties Description
SessionID The unique session identifier.
The value of the session state item with the specified name. This is the default
Item(name)
property of the HttpSessionState class.
Count The number of items in the session state collection.
Gets and sets the amount of time, in minutes, allowed between requests before
TimeOut
the session-state provider terminates the session.
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 16
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 17
If you create an 'Ajax Enabled site' or add an 'AJAX Web Form' from the 'Add Item' dialog box, the web form
automatically contains the script manager control.
The ScriptManager control takes care of the client-side script for all the server side controls.
The following table shows the properties of the update panel control:
Properties Description
This property indicates whether the post backs are coming from the child
ChildrenAsTriggers
controls, which cause the update panel to refresh.
It is the content template and defines what appears in the update panel
ContentTemplate
when it is rendered.
RenderMode Shows the render modes. The available modes are Block and Inline.
UpdateMode Gets or sets the rendering mode by determining some conditions.
Defines the collection trigger objects each corresponding to an event
Triggers
causing the panel to refresh automatically.
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 18
Methods Description
Creates a Control object that acts as a container for child
CreateContentTemplateContainer
controls that define the UpdatePanel control's content.
Returns the collection of all controls that are contained in the
CreateControlCollection
UpdatePanel control.
Initializes the UpdatePanel control trigger collection if partial-
Initialize
page rendering is enabled.
Update Causes an update of the content of an UpdatePanel control.
The behavior of the update panel depends upon the values of the UpdateMode property and ChildrenAsTriggers
property.
UpdateMode ChildrenAsTriggers Effect
Always False Illegal parameters.
UpdatePanel refreshes if whole page refreshes or a
Always True
child control on it posts back.
UpdatePanel refreshes if whole page refreshes or a
Conditional False
triggering control outside it initiates a refresh.
UpdatePanel refreshes if whole page refreshes or a
Conditional True child control on it posts back or a triggering control
outside it initiates a refresh.
<ProgressTemplate>
Loading...
</ProgressTemplate>
</asp:UpdateProgress>
The above snippet shows a simple message within the ProgressTemplate tag.
However, it could be an image or other relevant controls. The UpdateProgress control displays for every
asynchronous postback unless it is assigned to a single update panel using the AssociatedUpdatePanelID
property.
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 19
ii. Placing a timercontrol directly inside the UpdatePanel to act as a child control trigger. A single timer
can be the trigger for multiple UpdatePanels.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000"> </asp:Timer>
<asp:Label ID="Label1" runat="server" Height="101px" style="width:304px">
</asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 20
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit
Programming Using C# & .NET Module 4 & 5 21
Mrs. Suma M G, AP, Dept. of MCA, RNSIT for latest updates visit: www.google/+sumamgrnsit