ASP.NET Components - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

ASP.NET Components

Description:

Create a Web page to view a few columns. Create a separate Web page to insert, ... When calling the second Web page, pass the primary key as a Query String Parameter ... – PowerPoint PPT presentation

Number of Views:86
Avg rating:3.0/5.0
Slides: 11
Provided by: conest
Category:
Tags: asp | net | components | create | page | web

less

Transcript and Presenter's Notes

Title: ASP.NET Components


1
ASP.NET Components
Original slides by Kathleen Kalata Dave
Turton Modified by Meyer Tanuan
2
Maintaining Table with Many Columns
  • Showing many columns (gt7) in a DataGrid is
    difficult for users
  • Hands-on Assignment 6 Customer Maintenance
  • Create a Web page to view a few columns
  • Create a separate Web page to insert, update and
    delete a record.
  • When calling the second Web page, pass the
    primary key as a Query String Parameter

3
HyperLink Column in a DataGrid
  • To jump to another Web page
  • Add Hyperlink column
  • If using query parameter
  • set the URL field and URL format string ()

4
MTComponent WebForm1.aspx
5
.NET Components
  • A Component is a class containing one or more
    functions
  • These are typically compiled as separate
    assemblies (i.e., Class Library) for reuse
  • Assemblies (i.e., DLLs) can be used by other .NET
    languages

6
Coding a Componentadd new item ? component class
Add namespaces you expect to use
7
Using a Component
Try Dim CatList As MTComponent.Ch8Products
CatList New MTComponent.Ch8Products '
sample code for DL and DataReader
MyCatList.DataSource CatList.GetCat()
MyCatList.DataBind() ' sample code for DG
and DataReader DataGrid1.DataSource
CatList.GetCat() DataGrid1.DataBind()
Dim CatID As Integer CInt(Request.Params("CatID"
)) lblMessage.Text "CatId parameter value
" CatID.ToString Catch ex As Exception
lblMessage.Text ex.Message End Try
Declare a Component object
Create instance of component
Call components instance method
8
Exception Handling
  • Use Try / Catch / Finally Blocks
  • Code that may create a problem is placed in the
    try block
  • Code to deal with the problem (the exception
    handler) is placed in catch blocks
  • Within a Component, use System.Diagnostics.Debug.W
    riteLine() to display in VS.NET Output panel
  • Code to be executed whether an exception is
    thrown or not is placed in the finally block

9
Exception Handling Sample Code
Imports System.Diagnostics
Try SqlConnection1.Open()
Dim objCM As SqlCommand objCM New
SqlCommand(SQL, SqlConnection1) Dim
objDR As SqlDataReader objDR
objCM.ExecuteReader(CommandBehavior.CloseConnectio
n) Return objDR Catch ex As
Exception Debug.Write("GetCat ")
Debug.WriteLine(ex.Message)
Throw ex Finally SqlConnection1.Close()
-- if using DataSet End Try
10
Extra Using Session object
  • Session object maintains state across multiple
    Web page requests
  • To Store
  • Session(customer) aCustomer
  • To Access
  • Dim aCustomer As XXCustomer
  • aCustomer Session(customer)
  • Hands-on Assignment 6
  • Reference VS.NET Help Session State
Write a Comment
User Comments (0)
About PowerShow.com