Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

ASP.NET : ValidationSummary

ValidationSummary
This control use to show error messages of each Validation as a List or MessageBox.

ValidationSummary Properties
DisplayMode: Type of display error massage as a List, Bullet List or Single paragraph.
ShowMessageBox: Select "True" Display error massage as a MessageBox.
ShowSummary: Select "True" Display error massage as List at bottom of the page.

Other Validator Properties
Display: Select "None" to not display error message except in ValidationSummary.

Example
1. Create a ASP.NET website then add Standard TextBox, Validator and ValidationSummary. Need 2 or above Validation (See Example in Figure 1).


Figure 1: Example 

2. Select your ValidationSummary and set some properties that you want (This Example will show error message only in MessageBox (see Figure 1))

ValidationSummary PropertiesValue
DisplayModeList
ShowMessageBoxTrue
ShowSummaryFalse

Other Validator PropertiesValue
DisplayNone
Table 1: Example Properties

3. Test your application you will see error message only in MessageBox (Figure 2).

Figure 2: Example Application

##############################

 RequiredFieldValidator << Previous Chapter

ASP.NET : RequiredFieldValidator

RequiredFieldValidator 
This control not allow user skip an entry.

Example
1. Create a ASP.NET website then add Standard TextBox and RequiredFieldValidator.
2. Select your RangeValidator and set require properties for validate (see Table 1).


PropertiesValue
ControlToValidateTextBox1
ErrorMassagePlease Input Name !!

Table 1: Require Properties for RequiredFieldValidator

3. Test your application you will see error message when you don't entry anything in TextBox1 (Figure 1).


Figure 1: Require Check  Example

##############################

RangeValidaton << Previous Chapter || Next Chapter >> ValidationSummary

ASP.NET : RangeValidator

RangeValidator 
Check a number ranges with minimum and maximum number, alphabetic and Date.


Properties
Maximum Value: Highest value that you want to check.
Minimum Value: Lowest value that you want to check.
Type: Which Data Type that you want to check.


Example
1. Create a ASP.NET website then add Standard TextBox and RangeValidator.
2. Select your RangeValidatorand set require properties for validate (see Table 1).


PropertiesValue
ControlToValidateTextBox1
ErrorMassageYou are not 18-50 years old !!
MamimumValue50
MinimumValue18
TypeInteger

Table 1: Require Properties for RangeValidator


3. Test your application you will see error message when you input value that not in range (Figure 1).

Shorty Bluejova, Open Learning, Programming

Figure 1: Range Check  Example

##############################

CustomValidator << Previous Chapter || Next Chapter >> RequiredFieldValidator

ASP.NET : Custom Validator

Custom Validator
Checks the user's entry using validation logic that you write yourself. This type of validation enables you to check for values derived at run time.

Properties

ClientValidationFunction: Which JavaScript function that you want to check.

Example

1. Create a ASP.NET website then add Standard TextBox and CustomValidator.
2. Create your JavaScript Function for validate (For this example will check about input digits).

        <! Example !!>
        <head> <title>Test Validate</title>

        <script language="JavaScript">
           function checkDigit(source, agrs) {
               if(agrs.Value.length < 8 || agrs.Value.length > 12
                   args.IsValid = false;
               else
                   args.IsValid = true;
           }
        </script></head> 

3. Select your CustomValidator and set require properties for validate (see Table 1).



PropertiesValue
ClientValidationFunctioncheckDigit
ControlToValidateTextBox1
ErrorMassagePlease input 8-12 characters

Table 1: Require Properties for CustomValidator

4. Test your application you will see error message when you input wrong condition (Figure 1).


Figure 1: Custom Check  Example

##############################

CompareValidator (Check Data Type) << Previous Chapter || Next Chapter >> RangeValidator

ASP.NET : CompareValidator (Check Data Type)

Compare Validator
Compare a specify data type or Compare a user's entry value between two controls.

Properties (Data Type Checked)
Operator : Choose "DataTypeCheck"
Type : Which Data Type that you want to check.

Example Data Type Checked
1. Create a ASP.NET website then add Standard TextBox and CompareValidator.
2. Select your CompareValidator and set require properties for validate (see Table 1).


PropertiesValue
ControlToValidateTextBox1
ErrorMassageWrong !!
OperatorDataTypeCheck
TypeInteger

Table 1: Require Properties for Compare

3. Test your application you will see error message when you input wrong data type (Figure 1).



Figure 1: Data Type Check  Example


##############################

CompareValidator (Check Equal) << Previous Chapter || Next Chapter >> CustomValidator

ASP.NET : Page Life Cycle

Page Life Cycle
ASP.NET is a dynamic webpage that following sequential process steps include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. ASP.NET allowed you to write code at the appropriate Page Life Cycle stage for the effect you intend.

Figure 1: ASP.NET Page Life Cycle

See full step process here >> http://i.msdn.microsoft.com/dynimg/IC386473.png

Page Events
To manage your Page Life Cycle state, You should know some basic event first.
-  Page_Init() is the first occurs when an ASP.NET page is execute.
-  Page_Load() will occurs when all the objects on the page have been created and are available for use. 
-  Page_Unload() will occurs after everything else happens.

Post Back Events
Post Back event will occur only when a page is processed as a postback (When you click a button or something that send a data to server, postback will active and response a webpage to client again). You can check an postback with "if(Page.IsPostBack)" then it will return "true" if the page is being loaded in response to a client postback. Otherwise, if you just visit the page, a postback data is unknown or empry and it will return "false".

Example Postback (Code Behind Page)
Create a ASP.NET webpage and add one standard button for call postback.

protected void Page_Load(object sender, EventArgs e) {
   if (Page.IsPostBack)
      Response.Write("This is postback !!");
   else
      Response.Write("This is first time visit !!");
}

Figure 2: Example Result

##############################

Web Server Control << Previous Chapter || Next Chapter >> Validation Control

ASP.NET : Web Server Control

Web Server Controls
Like HTML server controls, Web server controls are also created on the server and they require a runat="server" attribute to work. However, Web server controls do not necessarily map to any existing HTML elements and they may represent more complex elements.

Figure 1: Web Server Control
Syntax
  <asp:controlname id="id" runat="server" />

Example
  Show ID and Name on the Label when click at the button

Figure 2: Webpage

Figure 3: Source code HTML


Figure 4: C# Code Behind Page
Code Behind Page
-  The code-behind page model allows you to keep the markup in one file—the .aspx file—and the programming code in another file. The name of the code file varies according to what programming language you are using
-  For example, if you are working with a page named SamplePage, the markup is in the file SamplePage.aspx and the code is in a file named SamplePage.aspx.cs (for C#), and so on

figure 4: Single and Separate File

Figure 5: Relation between HTML and Code Behind Page

##############################

HTML Server Control << Previous Chapter || Next Chapter >> Page Life Cycle

ASP.NET : Master and Child Page

Master Page
Acts as a template and merging container for pages that are composed only of Content controls and their respective child controls.
Figure 1: Master Page concept

How to Create Master Page (Visual Studio 2010) 
"Add new items" to your project and following this step.
Figure 2: Create Master Page

Figure 3: Source Code in Master Page

Child Page
Act as a content of pages that use same design form Master Page.

How to Create Child Page (Visual Studio 2010)
"Add new items" to your project and following this step. (If you see "Web Form using Master Page" you can selected  then choose your Master Page.)
Figure 4: Create Child Page

Figure 5:  Source Code in Child Page

############################## 

ASP.NET : HTML Server Control

HTML Server Control
- HTML elements in ASP.NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control.
- All HTML server controls must be within a <form> tag with the runat="server" attribute!
- ASP.NET requires that all HTML elements must be properly closed and properly nested.

HTML Control | Shorty Bluejova

Figure 1: HTML Control

Syntax
<taxname attribute=“value” runat=“server”>

Example
<input type=“text” id=“txtID” runat=“server”>
<input type=“button” id=“btnOK” onserverclick=“functionName” runat=“server”>

HTML Control | Shorty Bluejova
Figure 2: Implement with C# script inline code

Example II
1. Create Textbox and Password Textbox to receive Student ID and Password data from users.
2. Crate Division tag to show result of program at the end of HTML document.
3. Create Button to execute program.
4. If password is “BC” or “IT”, Response write text “Hello Student ID” and “Password Correct” in Division tag.
5. If not, write “Password is not Correct” in Division tag.

HTML Control | Shorty Bluejova
Figure 3: Implement with C# script inline code

Example III
Design and Program webpage to find net price (Vat 7%)

HTML Control | Shorty Bluejova
Figure 4: Webpage

HTML Control | Shorty Bluejova
Figure 5: Implement with C# script inline code

##############################

Introduction << Previous Chapter || Next Chapter >> Web Server Control

ASP.NET Introduction

The ASP.NET is a Microsoft’s free Web framework. It used to create dynamic and interactive Web applications, which are designed Website by using HTML and CSS in order to run them on the Internet by using Internet Information Service (IIS). It can use to create the database management on Website by using the ADO.NET (ActiveX Data Objects). The ASP.NET has two models for coding: the single-file page model and the code-behind page model. 

.NET Framework
The .NET is a Microsoft Programming platform for Microsoft Windows operating systems that supports the application and XML Web service for building and running. The .NET Framework could be consistent object-oriented programming, decreasing conflicts application and protected execution of code and it has many types of application such as Windows applications, Web applications and Mobile applications. The .Net Framework includes two major components: the Common Language Runtime (CLR) and .NET framework Class Library.

The Common Language Runtime (CLR)
The CLR is like a virtual machine application that uses to manage memory, thread execution, code execution and other system services. CLR is supports several programming languages that allows each languages can use code written in other languages (interoperability). The CLR is implementing from Common Language Infrastructure (CLI), which is an open specification that is developed by Microsoft. The CLI describes the executable code and runtime environment which are the core of the Microsoft .NET Framework and could lead users to the open source implementations. 

Figure 1: Common Language Infrastructure (CLI)

The .NET framework Class Library 
Class Library provides user interface, data access, database connectivity, cryptography, Web application development, numeric algorithms and network communications. Programmers can access the class library for combining it with their own code to produce applications because class library is an Object Oriented that has reusable common functionality. The .NET Framework can use to develop graphical user interface (GUI) applications to applications based on ASP.NET, such as Web Forms and XML Web services.

Today (February 10, 2011), the .NET Framework has a newest version which is version 4 including Parallel LINQ and Task Parallel Library that released on April 12, 2010 alongside Visual Studio 2010. Microsoft has started develops the .NET Framework since the late of 1990’s.


Figure 2: Microsoft's .NET Framework Version

##############################

Next Chapter >> HTML Server Control

ASP.NET : CompareValidator (Check Equal)

Compare Validator
Compare a specify data type or Compare a user's entry value between two controls.

Properties (Compare)
Operator : Choose "Equal"
ControlToCompare : Which control to compare.

Example Checke Equal
1. Create a ASP.NET website then add two Standard TextBox and one CompareValidator.
2. Select your CompareValidator and set require properties for validate (see Table 1).

Properties Value
ControlToCompare
TextBox1
ControlToValidate
TextBox2
ErrorMassage
Data does not match.
Operator
Equal


Table 1: Require Properties for Compare

3. Test your application you will see error message when both of TextBox is not have same value (Figure 1)

Figure 1: Compare Example

##############################

Validation Control << Previous Chapter || Next Chapter >> CompareValidator (Check Data Type)

ASP.NET : Validation Control

Validation Control
A Validation control is used to check the data of an user's entry on web server contols before you submit data to Server. If the data does not pass validation, it will display an error message.



Figure 1: Validation Control (Visual Studio 2010)

CompareValidatior : Compare a specify data type or Compare a user's entry value between two controls.
CustomValidator : Check a user's entry by validation logic and allow user's logic
RangeValidator : Check a number ranges with minimum and maximum number, alphabetic and Date.
RequiedFieldValidator : Not allow user skip an entry.
ValidationSummary : Show summary of Validation's error message in this control.

Basic Properties
ControlToValidate : Choose your Web Server Control that you want to check.
CssClass : Choose your CSS Class style.
Display : Default is "Static", Choose "none" if you want to show error message (for Summary).
EnableViewStateDefault is "True", Choose "False" to cancel View State.
ErrorMassage : When user's entry value is not validate, show text Message that you want.  

##############################



Validation Control << Previous Chapter || Next Chapter >> CompareValidator (Check Equal)

ASP.NET : Page Life Cycle

Page Life Cycle
ASP.NET is a dynamic webpage that following sequential process steps include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. ASP.NET allowed you to write code at the appropriate Page Life Cycle stage for the effect you intend.

Figure 1: ASP.NET Page Life Cycle

See full step process here >> http://i.msdn.microsoft.com/dynimg/IC386473.png

Page Events
To manage your Page Life Cycle state, You should know some basic event first.
-  Page_Init() is the first occurs when an ASP.NET page is execute.
-  Page_Load() will occurs when all the objects on the page have been created and are available for use. 
-  Page_Unload() will occurs after everything else happens.

Post Back Events
Post Back event will occur only when a page is processed as a postback (When you click a button or something that send a data to server, postback will active and response a webpage to client again). You can check an postback with "if(Page.IsPostBack)" then it will return "true" if the page is being loaded in response to a client postback. Otherwise, if you just visit the page, a postback data is unknown or empry and it will return "false".

Example Postback (Code Behind Page)
Create a ASP.NET webpage and add one standard button for call postback.

protected void Page_Load(object sender, EventArgs e) {
   if (Page.IsPostBack)
      Response.Write("This is postback !!");
   else
      Response.Write("This is first time visit !!");
}

Figure 2: Example Result

Next Chapter >>
Reference : 
http://msdn.microsoft.com/en-us/library/ms178472.aspx
Related Posts Plugin for WordPress, Blogger...