Topic/Name | Description | Code Links |
---|---|---|
Form Controls (WFC & HFC) Examples |
||
HTML Form Controls Example: | This example demonstrates the use of an HTML Form Control to submit a form for server-side processing, and it shows the ability to perform client-side validation, which can stop the form submission process. |
Demo ASPX Code Codebehind Code |
ASP.NET WebForm Controls Example: | This example demonstrates a simple ASP.NET Web Form Control used to submit a form for server-side processing. |
Demo ASPX Code Codebehind Code |
Controls Example 1: | This example demonstrates the use of a WFC button that executes server-side code and two HFC buttons that execute client-side code. |
Demo ASPX Code Codebehind Code |
Controls Example 2: | This example demonstrates the use of two HFC buttons that can submit a form that gets processed on the server-side. The server-side code cannot determine which HFC button submitted the form without extra code. When an HFC button is clicked, a JavaScript function sets a hidden field control's value corresponding to the button that was clicked, which the server-side code can use to determine the correct action to perform. |
Demo ASPX Code Codebehind Code |
Controls Example 3: | This example demonstrates the ability to perform client-side validation before submitting the form for server-side processing. By default, a WFC button always submits a form for server-side processing, but JavaScript can be used to do client-side processing and stop the form submission process when necessary. |
Demo ASPX Code Codebehind Code |
Controls Example 4: | This example demonstrates the ability to add HTML control events to a Web Form Control. By default, a Web Form Control doesn't have the onkeypress event that a normal HTML control has. This example shows how to add the event on the server-side and use it on the client-side. |
Demo ASPX Code Codebehind Code |
Request & Response Objects Example: | This example demonstrates the use of the Request object to retrieve data from HTML controls. The Response object is used to write data back to the client. The Request object contains data sent to the server in an HTTP Request, which includes the form's data. The Response object is used to store data in the HTTP Response that is sent back to the client. The example also shows how to submit the form for server-side processing from an HTML Form Control converted to a WFC with runat=server. |
Demo ASPX Code Codebehind Code |
HTML Form Processed by an ASPX Page Example: | This example demonstrates how to process a form in an HTML page using an ASPX dynamic server-page. |
Demo ASPX Code Codebehind Code |
Single-File Code Model (No CodeBehind) Examples |
||
No CodeBehind Example 1: | This example demonstrates the single-page model where server-side code and ASP/HTML mark-up code are intertwined. This model is stilled used by classic ASP, JSP, and PHP pages. It page doesn't use a CodeBehind. |
Demo ASPX Code |
No CodeBehind Example 2: | This example mixes server-side processing and client-side processing without a CodeBehind. One WFC button causes the form to submit for server-side processing. The other HFC button causes client-side processing. |
Demo ASPX Code |
No CodeBehind Example 3: | This example is the same as the previous example except that it counts and displays the number of times a button was clicked. The WFC button handles this with server-side code while the HFC handles this with client-side code. |
Demo ASPX Code |
Capitals Game with No CodeBehind: | This Web application allows you to play a guessing game with the State Capitols. It doesn't use a CodeBehind. |
Demo ASPX Code |
Capitals Game with CodeBehind: | This Web application allows you to play a guessing game with the State Capitols. It separates the ASP/HTML mark-up from the server-side code using a CodeBehind. |
Demo ASPX Code Codebehind Code |
GridView Examples |
||
GridView Example 1: | This example demonstrates dynamic data display using a GridView control bound to data coming from the database. The GridView automatically generates the columns for the grid based on the fields returned by the query. |
Demo ASPX Code Codebehind Code |
GridView Example 2: | This example demonstrates dynamic data display using a GridView control bound to data coming from the database. The GridView columns are manually created, not automatically generated like GridView Example 1. It allows the user to select a number of products by placing a check-mark in a CheckBox control and click the Order Products button. The server-side code determines which Checkboxes in the GridView were checked, gets the ProductID associated with the item, and displays a list of ProductIDs for the selected products (rows). The first column is s TemplateField, which allows the programmer to add a control like the CheckBox. The other columns are BoundFields, which are manually bound to specific fields from the query results it displays. |
Demo ASPX Code Codebehind Code |
GridView Example 3: | This example demonstrates the ability to use the GridView control to dynamically display data from the database and modify it. The GridView can handle a number of events that cause server-side code to execute. |
Demo ASPX Code Codebehind Code |
GridView Example 4: | This examples demonstrates the use of a footer to display information in the footer row of a GridView control. |
Demo ASPX Code Codebehind Code |
GridView Example 5: | This example demonstrates how to query and sort the data for a GridView to display. |
Demo ASPX Code Codebehind Code |
GridView Example 6: | This example demonstrates dynamic data display using a GridView control bound to data coming from an ArrayList of Product objects. The GridView automatically generates the columns for the grid based on the public properties of the Product class objects stored in the ArrayList. |
Demo ASPX Code Codebehind Code Product Class Code |
GridView Example 7: | This example does the same thing as GridView Example 3 except that it manipulates data in an ArrayList instead of a database. |
Demo ASPX Code Codebehind Code Product Class Code |
GridView Example 9: | This example uses a drop-down list to update a GridView. The drop-down list is bound to data coming from the database. A PostBack is issued each time a new item is selected from the drop-down, which will update the data in the GridView. |
Demo ASPX Code Codebehind Code |
GridView Example 10: | This example demonstrates merging two datasets into one dataset and displaying the resulting dataset in a GridView. |
Demo ASPX Code Codebehind Code |
GridView Example 11: | This example demonstrates the GridView's paging feature to display a large number of records using pages. |
Demo ASPX Code Codebehind Code |
GridView Example 12: | This example demonstrates the ability to store and retrieve key values in the GridView without displaying them in a GridView's column. The GridView's DataKeys collection is used to store each record's primary key (product number). |
Demo ASPX Code Codebehind Code |
Managing & Maintaining State Examples |
||
Session Example 1: | This example demonstrates the use of the Session object to allow data to persist between postbacks and multiple pages of a Web Application. |
Demo ASPX Code Codebehind Code Results Page ASPX Code Results Page Codebehind Code |
Session Example 2: | This example uses the Global.asax page to execute code when a new session begins. When a new session begins, data is retrieved from the database. The data retrieved from the database is stored in the Session object and used by multiple pages instead of making multiple connections to the database. |
Demo ASPX Page 1 Code Page 1 Codebehind Code ASPX Page 2 Code Page 2 Codebehind Code Global.asax Codebehind Code |
Application Example 1: | This example uses the Application object to store data that can be accessed by separate sessions using the Web Application. The application is a voting machine that stores the votes for all the candidates in the Application object, which each user (session) can view and update the shared data. Data stored in the Application object suffer from concurrency issues. This example shows how to use shared data in a safe way with the Application.Lock() and Application UnLock() methods |
Demo ASPX Code Codebehind Code Global.asax Codebehind Code Results Page ASPX Code Results Page Codebehind Code |
Cookies Example: | This example demonstrates writing and reading a cookie to save data for a single user between multiple sessions. |
Demo ASPX Code Codebehind Code |
HTTP QueryString Example: | This example demonstrates the use of the HTTP GET method for sending form data in the URL of the HTTP Request, and how to retrieve data from the URL used in server-side processing of the form. |
Demo ASPX Code Codebehind Code ASPX Code Codebehind Code |
Dynamic Data Display Examples (without a GridView) |
||
Dynamic Display Example 1: | This example demonstrates dynamic data display without using a GridView control. An HTML table is generated on the server-side with the data retrieved from the database. The dynamically generated HTML string is then inserted into the page using a server-side DIV control. |
Demo ASPX Code Codebehind Code |
Dynamic Display Example 2: | This example is a copy of Dynamic Display Example 1 with one addition: it demonstrates how to dynamically create a Textbox to display database data, and how to render it into HTML that gets put into the server-side DIV for display. |
Demo ASPX Code Codebehind Code |
Dynamic Display Example 3: | This example is a copy of Dynamic Display Example 2 done in a different method. In the previous examples the HTML was generated manually through code, but this example uses some controls that handle the rendering of the HTML. It uses a PlaceHolder control to insert a table created using an object-oriented approach. The PlaceHolder control is responsible for rendering the objects it contains into HTML. A Table object is created with TableRow and TableCell objects. Some TableCell objects contain database data as text while others contain dynamically created controls like a TextBox and Button. This example also demonstrates how to add a button dynamically and wire an event that can be processed on the server-side. |
Demo ASPX Code Codebehind Code |
Repeater Examples |
||
Repeater Example 1: | This example demonstrates dynamic data display using a Repeater control bound to data coming from the database. The Repeater generates the table-like grid based on the records and fields returned by the query, but it requires manually editing the ASP/HTML mark-up. |
Demo ASPX Code Codebehind Code |
Repeater Example 2: | This example demonstrates dynamic data display using a Repeater control bound to data coming from an ArrayList of Product objects. |
Demo ASPX Code Codebehind Code |
Repeater Example 3: | This example is a copy of Repeater Example 1 with one addition: each row in the repeater contains a button that causes a server-side event. All the buttons in the Repeater fire the same event, so this example demonstrates how to determine which button caused the event. |
Demo ASPX Code Codebehind Code |
Database Examples |
||
Identity Field Example 1: | This example demonstrates how to retrieve the primary key field's value (Identity Field) for a field that is automatically handled by the database. This approach is needed when an application needs to know the automatically generated value for a newly added record. |
Demo ASPX Code Codebehind Code |
Stored Procedure Example 1: | This example demonstrates the use of Stored Procedures to perform secure operations within a database server. The Stored Procedures used in this example perform SQL SELECT statements to return the results of a query. This example also shows how to pass an input parameter for a Stored Procedure to use in a query. |
Demo ASPX Code Codebehind Code Stored Procedures Code |
Stored Procedure Example 2: | This example demonstrates the use of Stored Procedures to update data in the database. |
Demo ASPX Code Codebehind Code Stored Procedures Code |
Stored Procedure Example 3: | This example demonstrates the use of Stored Procedure transactions that can roll-back changes when errors are detected. |
Demo ASPX Code Codebehind Code Stored Procedures Code |
Serialization Example 1: | This example demonstrates how to use Serialization to store an application's object as binary data in the database. It also demonstrates how to use Deserialization to recreate the object in memory for the application to use after it's retrieved from the database. |
Demo ASPX Code Codebehind Code Stored Procedures Code CreditCard Class Code |
Working with Images Example - Writing Images to a Database & Retrieving Images from a Database: |
This example shows how to upload an image file using a FileUpload control, relate it to an existing database record, and store it in the database. It also demonstrates how to retrieve the binary image data from the database and put it into a GridView ImageField through the use of a handler (another ASPX page to process the image data). |
No Demo Available Product Loader ASPX Code Product Loader Codebehind Code Product Viewer ASPX Code Product Viewer Codebehind Code Product Image Grab (Handler) ASPX Code Product Image Grab (Handler) Codebehind Code Stored Procedures Code |
Working with Images Example 2 | This example shows how to retrieve binary image data from the database and put it into a GridView ImageField using a simpler method. |
Demo ASPX Code Codebehind Code |
Validator Control Examples |
||
Validators Example 1: | This example demonstrates the use of simple validation controls that can validate user input on both the client and server sides. ASP.NET Validation controls perform client-side validation to prevent a round-trip to the server when the input isn't valid. However, the server also performs validation even when the client-side validation was successful; this is necessary because a browser may disable scripting and bypass client-side validation. |
Demo ASPX Code Codebehind Code |
Validators Example 2: | This example demonstrates the use of a ValidationSummary control to organize error messages related to a number of validation controls. |
Demo ASPX Code Codebehind Code |
Validators Example 3: | This example demonstrates validating an ASPX page's data using server-side code before the Page_Load event. It allows the programmer to determine when a page's input is valid. |
Demo ASPX Code Codebehind Code |
Web API & Web Service Examples |
||
ASP.NET Core Web API Example: | This example shows how to create a RESTful Web API using ASP.NET Core and consume the Web API in different client applications. |
Web API Code Team Class Code ASPX Client Demo ASPX Client - ASPX Code ASPX Client - Codebehind Code ASPX Client Demo 2 ASPX Client - ASPX Code ASPX Client - Codebehind Code JQuery Client Demo JQuery Client Code JavaScript Client Demo JavaScript Client Code |
ASP.NET Core Web API Example: | This example demonstrates how to call a RESTful Web API's methods to perform a task. Web API's allow distributing the workload between multiple computers instead of all the server-side code executing on one server. |
Demo Web API Code Web API Client - ASPX Code Web API Client - Codebehind Code |
ASP.NET Core Web API Example: | This example demonstrates how to pass user-defined class types (UDT) to a Web API and receive a user-defined type as the return value from Web API. This example also demonstrates how to return a collection from a Web API. |
Demo Web API Code Web API - Customer class Web API Client - ASPX Code Web API Client - Codebehind Code |
ASP.NET Core Web API Example (Session Management): | This example demonstrates the use of Session Management to persist data between multiple Web API and Web API Client requests. By default, a Web API doesn't handle the use of Sessions and Session data. This requires enabling Session management through code in the Web API's Startup.cs configuration file and creating a cookie container for the Web Request to store the Session Cookie on the Web API Client (ASPX server-side code). |
Demo Web API - Codebehind Code Web API Client - ASPX Code Web API Client - Codebehind Code Web API Client Results Page - ASPX Code Web API Client Results Page - Codebehind Code |
ASMX Web Service Example 1: | This example is identical to the Web API example that provides a simple calculator service except that it demonstrates how to call an ASMX Web Service to perform the tasks. Web Service's allow distributing the workload between multiple computers instead of all the server-side code executing on one server. The Web Service Proxy object is used to communicate with the Web Service, invoke a Web Method, pass it input, and receive the result. |
Demo Web Service - (ASMX) Codebehind Code Web Service Client - ASPX Code Web Service Client - Codebehind Code |
ASMX Web Service Example 2: | This example is identical to the Web API example that provides customer service operations except that it uses an ASMX Web Service to perform the tasks. This example demonstrates how to pass user-defined class types (UDT) to a Web Service Web Method and receive a user-defined type as the return value of Web Method. Sending and receiving user-defined types is a different process than using simple data types like string, int, double, etc... This example also demonstrates how to return an ArrayList from a Web Method. |
Demo Web Service - (ASMX) Codebehind Code Web Service - Customer class Web Service Client - ASPX Code Web Service Client - Codebehind Code |
ASMX Web Service Example 3 (Session Management): | This example demonstrates the use of Session Management to persist data between multiple Web Service and Web Service Client requests. By default, a Web Service disables the use of Session data. This requires enabling Session management through code in the Web Service and creating a container for the Web Service Proxy object to store the Session Cookie on the Web Service Client (ASPX server-side code). |
Demo Web Service - (ASMX) Codebehind Code Web Service Client - ASPX Code Web Service Client - Codebehind Code Web Service Client Results Page - ASPX Code Web Service Client Results Page - Codebehind Code |
Core MVC Web Application Examples |
||
Dynamic Data Display Example: | This example demonstrates dynamic data display using a Weakly-Typed Razor View. The Controller passes a collection to the View using the ViewBag/ViewData collection, which is used to dynamically generate the content for the View.The example also demonstrates processing a simple search tool that updates the display. |
Demo Razor View Code Controller Code |
Dynamic Data Display Example 2: | This example demonstrates dynamic data display using a Strongly-Typed Razor View. The Controller passes a collection to the View using a Model attached to the View. The View's Model is a collection of Car objects, which is used to dynamically generate the content for the View.The example also demonstrates processing a simple search tool that updates the display. |
Demo Razor View Code Controller Code |
Dynamic Data Display Example 3: | This example demonstrates dynamic data display using a Strongly-Typed Razor View to display a single Car's detailed information. The Controller passes a single Car object to the View using a Model attached to the View. The View's Model is a single Car object that is used to dynamically generate the content for the View.The example also demonstrates passing data to the Controller using routing parameters embedded in the URL. |
Demo Razor View Code Controller Code |
Simple Form Processing Example: | This example demonstrates processing a form within a Razor View. The form data is submitted using an HTTP Post to a Core MVC Controller. The controller accesses the form data from the Request.Form["key"] collection. |
Demo Razor View Code Controller Code |
Form Processing Example 2: | This example demonstrates processing a simple HTML form in a Weakly-Typed View without a Model. The form controls use the name and id attributes that the Model Binder component will map to the CarsController's method input parameters. The names and ids must exactly match the Controller method's input parameters. |
Demo Razor View Code Controller Code |
Form Processing Example 3: | This example demonstrates processing a form using Strongly-Typed View that uses a Car Model object attached to the View. It also uses HTML tag helpers to help write the HTML for the page. |
Demo Razor View Code Controller Code |
Customer User Control Examples |
||
Customer User Control Example 1: | This example demonstrates how to use a Custom User Control (ASCX) that displays a records data, and how to dynamically load an instance of this Custom User Control for each record returned by a database query. The Custom User Control exposes properties and methods that can be used from an ASCX page that uses this control. |
Demo Page that uses the Custom User Control - ASPX Code Page that uses the Custom User Control - Codebehind Code Custom User Control - (ASCX) Markup Code Custom User Control - (ASCX) Codebehind Code |
Customer User Control Example 2: | This example is a simple example of using a Custom User Control. The previous example dynamically loads the control for the page, but this example demonstrates how to use a single Custom User Control that was manually added to the page in the ASPX mark-up (GUI). |
Demo Page that uses the Custom User Control - ASPX Code Page that uses the Custom User Control - Codebehind Code Custom User Control - (ASCX) Markup Code Custom User Control - (ASCX) Codebehind Code |
Miscellaneous Examples |
||
Email Example: | This example demonstrates how to create an email object and send it using SMTP. |
Demo ASPX Code CodeBehind Code Email Class Code Web.config File Settings for SMTP mail (not needed for this example) |
Security Examples |
||
SSL Secure Connections Example: | This example demonstrates how to set-up a secure SSL connection between the browser and Web server. This example also shows how to detect whether or not there is a secure connection when the page loads. The secured page (SecurityDemo.aspx) causes a redirect whenever there isn't a secure connection; thus, it restricts the user from viewing the page until a secure SSL connection has been established. The example will cause a browser security issue that states the certificate is untrusted. The CIS-IIS2 Web server uses a trial testing certificate that is used for testing purposes; it cannot be validated with a certificate authority, which is the reason for the browser security message. |
Demo ASPX Code CodeBehind Code Secured Page ASPX Code Secured Page CodeBehind Code |
Symmetric Encryption Example: | This example demonstrates how to securely save a password in a cookie that can be used for automatic logins. This example takes the password as plain-text and encrypts it using AES Rijndael's Symmetric Encryption Algorithm, and stores the username and the encrypted password in a cookie. It also demonstrates how to read the password from the cookie and decrypt it. |
Demo ASPX Code CodeBehind Code |
AJAX Examples |
||
Simple AJAX Example 1: | This example demonstrates the ability to make an asynchronous request from client-side JavaScript to retrieve a quote from the Web server. When the response from the server is received, the client-side script updates the page with the newly retrieved quote. |
Demo HTML/JavaScript Code ASPX CodeBehind Code |
Simple AJAX Example 1 version 2: | This example is the same as Simple AJAX Example 1 except that it uses a try-catch statement to determine the browser's ability to handle AJAX. |
Demo HTML/JavaScript Code ASPX CodeBehind Code |
Simple AJAX Example 2: | This example demonstrates the ability to have a simple HTML form processed by an ASPX page using AJAX and the POST method of sending form data. |
Demo HTML/JavaScript Code ASPX CodeBehind Code |
Simple AJAX Example 2 version 2: | This example demonstrates the ability to have a simple HTML form processed by an ASPX page using AJAX and the GET method of sending form data. |
Demo HTML/JavaScript Code ASPX CodeBehind Code |
Predictive Fetch Example: | This example demonstrates the use of the Predictive Fetch Design Pattern to get the player's statistics before the user clicks a button to display the statistics. The user chooses a player from the drop-down box, which causes a server-side event that displays the appropriate player picture. This is a normal client-server request and response interaction. The predictive fetch occurs after the client-side page load, which makes an AJAX asynchronous request to the server to get the player's statistics before the user clicks the button to show it. The button's click event simply needs to take the pre-fetched, predicted data and place it in a DIV. |
Demo ASPX Code CodeBehind Code MLB Web API - (Core 2.0) CodeBehind Code Demo ASPX Code CodeBehind Code MLB Web Service - (ASMX) CodeBehind Code |
Submission Throttling Example: | This example demonstrates the use of the Submission Throttling Design Pattern that submits the form for processing at certain periodic intervals (every 3 seconds) using AJAX. |
Demo ASPX Code (No code in CodeBehind) Web API - (Core 2.0) CodeBehind Code Demo ASPX Code (No code in CodeBehind) Web Service - (ASMX) CodeBehind Code |
Payment Processing Examples |
||
Authorize.Net Payment Processing Example: | This example demonstrates the use of Authorize.Net as a payment gateway to process a credit-card transaction. This example also demonstrates how to create a Web HTTP Request in server-side code to send the credit card information, and receive a Web HTTP Response from the payment gateway. |
Demo ASPX Code CodeBehind Code Payment Page ASPX Code Payment Page CodeBehind Code |