Giáo trình Visual Studio 2008 - Microsoft ASP.NET 3.5

MỤC LỤC

Chƣơng 1. Lập trình Web & ASP.NET . 1

1.1. Giới thiệu về ứng dụng Web . 1

1.2. Giới thiệu về ASP và ASP.NET . 4

1.3. Web Server IIS . 10

1.4. Tạo ứng dụng Web với ASP.NET . 13

1.5. Khảo sát giao diện Visual Studio .NET 2008 . 16

1.6. Bài thực hành chương 1. 19

Chƣơng 2. Tìm hiểu và sử dụng các Server Controls . 21

2.1. Cấu trúc trang ASP.NET . 21

2.2. Biến cố trang ASP.NET . 26

2.3. Giới thiệu ASP.NET Server Controls . 28

2.4. HTML Server Controls . 29

2.5. ASP.NET Server Controls . 52

2.6. Sự kiện PageLoad và thuộc tính IsPostBack . 79

2.7. Thuộc tính AutoPostBack của một số Web Server Controls . 83

2.8. Bài thực hành chương 2. 88

Chƣơng 3. Master Page – Web Navigation . 94

3.1. Master Page . 94

3.2. Web Navigation . 104

3.3. Web User Control . 113

3.4. Đối tượng Request, Response và Server . 122

3.5. Bài thực hành chương 3. 131

Chƣơng 4. Quản lý trạng thái . 137

4.1. Vấn đề trạng thái . 137

4.2. Xem trạng thái (View State) . 138

4.3. Chuyển thông tin giữa các trang . 140

4.4. Đối tượng Cookies . 145

4.5. Đối tượng Session . 148

4.6. Đối tượng Application . 150

4.7. Tập tin Global.asax. 153

4.8. Tập tin Web.config . 154

4.9. Bài tập chương 4 . 157

Chƣơng 5. Sử dụng các Validation Controls . 160

5.1. RequiredFieldValidator . 161

5.2. Điều khiển RangeValidator . 164

5.3. Điều khiển CompareValidator . 166

5.4. Điều khiển RegularExpressionValidator . 169

5.5. Điều khiển Custom Validator . 172

5.6. Điều khiển ValidationSummary . 174

5.7. Bài thực hành chương 5. 179

Chƣơng 6. Các đối tƣơng dữ liệu (Rich Controls – Login . 183

6.1. Điều khiển hiển thị các trang khác nhau MultiView. . 183

6.2. Điểu khiển Wizard. 190

6.3. Nhóm Điều khiển Login . 197

6.4. Bài tập chương 6 . 203

Chƣơng 7. Giới thiệu ADO.NET . 216

7.1. Kiến trúc ADO.NET. 216

7.2. Tìm hiểu trình cung cấp dữ liệu của ADO.NET . 217

7.3. Các namespace của ADO.NET . 219

7.4. Tìm hiểu cơ chế kết nối của ADO.NET qua Connected Layer . 223

7.6. Disconnected Layer . 247

7.7. Đối tượng dữ liệu SqlDataSource . 256

7.8. Bài tập chương 7 . 264

Chƣơng 8. Tìm hiểu và ứng dụng cơ chế Data Binding . 268

8.1. Các dạng Data Binding. . 268

8.2. Bài tập chương 8 . 274

Chƣơng 9. Các đối tƣơng dữ liệu (Data Controls) . 279

9.1. Đối tượng dữ liệu GridView. . 279

9.2. Đối tượng dữ liệu DetailsView . 299

9.3. Đối tượng dữ liệu FormView . 302

9.4. Đối tượng dữ liệu DataList . 304

9.5. Đối tượng dữ liệu Repeater . 308

9.6. Bài thực hành chương 9. 310

Chƣơng 10. Bảo mật các ứng dụng Web . 312

10.1. Giới Thiệu về Bảo Mật Trong ASP.Net. . 312

10.2. Thí dụ minh họa . 313

Chƣơng 11. Giới thiệu AJAX . 319

11.1. Giới thiệu Ajax. . 319

11.2. Ajax làm việc như thế nào? . 319

11.3. ASP.Net Ajax Server Control . 328

11.4. Giới thiệu Ajax Toolkit 3.5 . 331

11.5. Tìm hiểu một số điều khiển trong Ajax Toolkit 3.5. 336

11.6. Bài thực hành chương 11 . 382

Chƣơng 12. Lập trinh LINQ . 396

12.1. Giới Thiệu LINQ. . 396

12.2. Các Khái Niệm Cơ Bản . 398

12.3. LINQ to Objects . 404

12.4. LINQ to DataSet . 405

12.5. LINQ to SQL . 408

Chƣơng 13. Lập trình Web Services . 415

13.1. Giới thiệu Web services. . 415

13.2. Kiến trúc và các thành phần Web services . 416

13.3. Xây Dựng Ứng Dụng Web Service . 420

Chƣơng 14. Xây dựng Website bán hàng . 427

Chƣơng 15. Thiết kế Website bán hàng –Mức dữ liệu . 436

Chƣơng 16. Thiết kế Website bán hàng –Mức xử lý . 451

Chƣơng 17. Thiết kế Website bán hàng –Mức trình diễn . 474

pdf502 trang | Chuyên mục: ASP.NET | Chia sẻ: dkS00TYs | Lượt xem: 2503 | Lượt tải: 1download
Tóm tắt nội dung Giáo trình Visual Studio 2008 - Microsoft ASP.NET 3.5, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
ist_ItemCommand" 
 onitemdatabound="list_ItemDataBound"> 
 <asp:HyperLink ID="hplnkName" Height="30px" runat="server" 
NavigateUrl='' Text='<%# 
HttpUtility.HtmlEncode(Eval("TenSanPham").ToString()) %>'> 
Lưu hành nội bộ Trang 482 
 <td style="padding-left:10px;border-left-color:Green; border-left-style:solid; 
border-left-width:1px"> 
 <a href="<%# LinkBuilder.ToProduct(Eval("MaSanPham").ToString()) 
%>"> 
 <img width="100px" height="110px" src="<%# 
LinkBuilder.ToProductImage(Eval("Thumbnail").ToString()) %>" border="0" alt="<%# 
HttpUtility.HtmlEncode(Eval("TenSanPham").ToString())%>"><br style="line-
height:9px"> 
 <%# 
HttpUtility.HtmlEncode(Eval("MoTaSanPham").ToString()) %> 
 <asp:LinkButton ID="btnAddToCart" runat="server" Text="Thêm vào 
giỏ" Width="100px"> 
 <td style="padding-left:10px;border-left-color:Green; border-left-style:solid; 
border-left-width:1px"> 
 ' 
/> 
 <asp:Label ID="lblPrice" runat = 
"server" Text=''> 
Lưu hành nội bộ Trang 483 
 <td colspan="6" style="background:url(images/1_bg1.gif); width:1px; 
height:1px"> 
 var lblprice,ddlist,hidden; 
 function Select1_onchange(seft,lblPrice,hd) { 
 lblprice = lblPrice; 
 ddlist = seft; 
 hidden = hd; 
CurrencyService.GetCurrency(lblPrice,document.getElementById(hd).value,seft.value,Comple
te,Error); 
 } 
 function Error(result) 
 { 
 ddlist.value = "USD"; 
 alert("Vui lòng thử lại sau"); 
 } 
 function Complete(result) 
 { 
 document.getElementById(lblprice).innerHTML= result; 
 } 
6. chỉnh sửa lại file ProductsList.ascx.cs: 
using System; 
Lưu hành nội bộ Trang 484 
using System.Collections; 
using System.Web.UI.WebControls; 
using System.Globalization; 
using CurrencyWS; 
public class MyCompareClass : IComparer 
{ 
 int IComparer.Compare(Object x, Object y) 
 { 
 return (string.Compare(x.ToString(), y.ToString())); 
 } 
} 
public partial class UserControl_ProductsList : System.Web.UI.UserControl 
{ 
 private void InitializeComponent() 
 { 
 } 
 protected void Page_Load(object sender, EventArgs e) 
 { 
 if (!IsPostBack) 
 { 
 InitCurrencyRate(); 
 PopulateControls(); 
 } 
 } 
 private void InitCurrencyRate() 
 { 
 if (Session["BookStoreCurrency"] == null) 
 { 
 hdRate.Value = "1"; 
 ddlCurrency.SelectedIndex = 0; 
 Session["BookStoreCurrency"] = "0,USD"; 
 } 
 else 
 { 
 string[] CurrencyInfo = (Session["BookStoreCurrency"].ToString()).Split(','); 
 ddlCurrency.SelectedIndex = Int32.Parse(CurrencyInfo[0]); 
 CurrencyConvertor currencyConvertor = new CurrencyConvertor(); 
 if (CurrencyInfo[1] != "USD") 
 try 
 { 
 hdRate.Value = (currencyConvertor.ConversionRate(Currency.USD, 
(Currency)Enum.Parse(typeof(Currency), CurrencyInfo[1]))).ToString(); 
 } 
 catch 
 { 
 ddlCurrency.SelectedIndex = 0; 
 hdRate.Value = "1"; 
 } 
 else 
Lưu hành nội bộ Trang 485 
 hdRate.Value = "1"; 
 } 
 } 
 private void PopulateControls() 
 { 
 string departmentId = Request.QueryString["DepartmentID"]; 
 string categoryId = Request.QueryString["CategoryID"]; 
 string page = Request.QueryString["Page"]; 
 string searchString = Request.QueryString["Search"]; 
 string dpId = Request.QueryString["dpid"]; 
 if (page == null) page = "1"; 
 int howManyPages = 1; 
 string firstPageUrl = ""; 
 string pagerFormat = ""; 
 string currentpage = Request.AppRelativeCurrentExecutionFilePath; 
 if (String.Compare(currentpage, "~/NewestProducts.aspx", true) == 0) 
 { 
 DateTime from = new DateTime(2009,10,1,12,0,0); 
 list.DataSource = CatalogAccess.GetNewestProducts(from, 
DateTime.Now,OnlineStoreConfigurations.ProductDescriptionLength,Int32.Parse(page),Onlin
eStoreConfigurations.ProductsPerPage,out howManyPages); 
 list.DataBind(); 
 firstPageUrl = LinkBuilder.ToNewestProducts("1"); 
 pagerFormat = LinkBuilder.ToNewestProducts("{0}"); 
 } 
 else 
 if (String.Compare(currentpage, "~/BestSellerProducts.aspx", true) == 0) 
 { 
 list.DataSource = 
CatalogAccess.GetBestSellerProducts(OnlineStoreConfigurations.ProductDescriptionLength, 
Int32.Parse(page), OnlineStoreConfigurations.ProductsPerPage, out howManyPages); 
 list.DataBind(); 
 firstPageUrl = LinkBuilder.ToBestSellerProducts("1"); 
 pagerFormat = LinkBuilder.ToBestSellerProducts("{0}"); 
 } 
 else 
 if (searchString != null) 
 { 
 string allWords = Request.QueryString["AllWords"]; 
 list.DataSource = CatalogAccess.Search(searchString, dpId, Int32.Parse(page), 
OnlineStoreConfigurations.ProductsPerPage,out howManyPages); 
 list.DataBind(); 
 // Display pager 
 firstPageUrl = LinkBuilder.ToSearch(searchString, dpId, "1"); 
 pagerFormat = LinkBuilder.ToSearch(searchString, dpId, "{0}"); 
 if (list.Items.Count == 0) 
 lblError.Text = "Không có sản phẩm nào"; 
Lưu hành nội bộ Trang 486 
 } 
 else 
 if (categoryId != null) 
 { 
 list.DataSource = CatalogAccess.GetProductsInCategory(categoryId, page, out 
howManyPages); 
 list.DataBind(); 
 firstPageUrl = LinkBuilder.ToCategory(departmentId, categoryId, "1"); 
 pagerFormat = LinkBuilder.ToCategory(departmentId, categoryId, "{0}"); 
 } 
 else 
 if (departmentId != null) 
 { 
 list.DataSource = CatalogAccess.GetProductsOnDeptPromo(departmentId, 
page, out howManyPages); 
 list.DataBind(); 
 firstPageUrl = LinkBuilder.ToDepartment(departmentId, "1"); 
 pagerFormat = LinkBuilder.ToDepartment(departmentId, "{0}"); 
 } 
 else 
 { 
 list.DataSource = CatalogAccess.GetProductsOnFrontPromo(page, out 
howManyPages); 
 list.DataBind(); 
 howManyPages = 1; 
 } 
 topPager.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, true); 
 bottomPager.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, true); 
 } 
 protected void list_ItemCommand(object source, 
System.Web.UI.WebControls.DataListCommandEventArgs e) 
 { 
 DataListItem items = e.Item; 
 string productId = list.DataKeys[e.Item.ItemIndex].ToString(); 
 ShoppingCartAccess.AddToShoppingCart(productId); 
 Response.Redirect(Request.RawUrl); 
 } 
 public string FormatCurrency(double price) 
 { 
 NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat; 
 return price.ToString("N",nfi); 
 } 
 protected void list_SelectedIndexChanged(object sender, EventArgs e) 
 { 
 } 
 protected void list_ItemDataBound(object sender, DataListItemEventArgs e) 
 { 
Lưu hành nội bộ Trang 487 
 Label lblPrice = e.Item.FindControl("lblPrice") as Label; 
 HiddenField hd = e.Item.FindControl("hd") as HiddenField; 
 NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat; 
 double dprice = Double.Parse(hd.Value) * Double.Parse(hdRate.Value); 
 lblPrice.Text = dprice.ToString("N", nfi) + " " + 
(Session["BookStoreCurrency"].ToString()).Split(',')[1]; 
 //} 
 } 
 protected void ddlCurrency_SelectedIndexChanged(object sender, EventArgs e) 
 { 
 if (ddlCurrency.SelectedValue != "USD") 
 { 
 try 
 { 
 CurrencyConvertor currencyConvertor = new CurrencyConvertor(); 
 hdRate.Value = (currencyConvertor.ConversionRate(Currency.USD, 
(Currency)Enum.Parse(typeof(Currency), ddlCurrency.SelectedValue))).ToString(); 
 } 
 catch 
 { 
 hdRate.Value = "1"; 
 ddlCurrency.SelectedIndex = 0; 
 lblError.Text = "Có lỗi trong quá trình chuyển đổi, vui lòng thử lại sau!"; 
 } 
 } 
 else 
 { 
 hdRate.Value = "1"; 
 } 
 Session["BookStoreCurrency"] = 
ddlCurrency.SelectedIndex.ToString()+","+ddlCurrency.SelectedValue; 
 PopulateControls(); 
 Response.Redirect(Request.RawUrl); 
 } 
} 
Mỗi khi ProductsList được load lại sẽ căn cứ vào query string đễ láy được danh sách sản 
phẩm tương ứng. Như vậy, khi muốn load danh sách sản phẩm cho một trang nào đó trên 
website thì ta chỉ cần sử dụng ProductsList User control này. 
Sau đây là một số giao diện chính của website: 
Lưu hành nội bộ Trang 488 
1. Trang chủ 
Ở trang này người dùng có thể xem các loại sách, đăng nhập, đăng ký, tìm kiếm 
Thanh tìm 
kiếm sách 
Thông tin về sách 
như tên sách, hình 
ảnh, giá tiền… 
Các thể loại 
sách chính 
Service chuyển 
đổi tiền tệ 
Thông tin 
đăng nhập 
Lưu hành nội bộ Trang 489 
2. Trang đăng ký 
Cho phép người dùng đăng ký một tài khoản để có thể sử dụng đầy đủ các chức năng của 
trang web. 
Các thông tin cần thiết khi 
người dùng đăng ký tài khoản 
Lưu hành nội bộ Trang 490 
3. Trang đăng nhập 
 Người dùng phải nhập chính xác thông tin tài khoản và mật khẩu. 
Nếu người dùng đăng nhập thành công. 
Thông tin về sách 
như tên sách, hình 
ảnh, giá tiền… 
Chào mừng tài khoản đã 
đăng nhập thành công 
Trang quản lý tài 
khoản của người dùng 
Lưu hành nội bộ Trang 491 
4. Trang các loại sách 
 Sách Khoa học 
Thông tin về sách thuộc 
thể loại Khoa Học 
Các thể loại 
sách con 
Lưu hành nội bộ Trang 492 
5. Trang chi tiết sản phẩm 
Các loại tiền tệ có thể chuyển đổi: 
Thêm sản phẩm 
vào giỏ hàng 
Tên sách 
Tìm sản phẩm 
tương tự trên 
Amazon 
Tìm sản phẩm 
tương tự trên Ebay Chuyển đổi tiền tệ 
Lưu hành nội bộ Trang 493 
Những sản phẩm tương tự trên Amazon 
Lưu hành nội bộ Trang 494 
 Những sản phẩm tương tự trên Ebay 
Lưu hành nội bộ Trang 495 
6. Trang quản lý tài khoản user 
Lưu hành nội bộ Trang 496 
7. Trang giỏ hàng 
Tiếp tục quá trình 
mua sách Tới trang đặt hàng 
Lưu hành nội bộ Trang 497 
8. Trang đặt hàng 
Service chuyển 
đổi tiền tệ 
Chuyển lên trang PayPal 
để thanh toán 
Lưu hành nội bộ Trang 498 
9. Trang quản lý 
 Quản lý đơn đặt hàng 
Các loại sách 
Thêm loại sách 
Các thực đơn 
chức năng 
Lưu hành nội bộ Trang 499 
Các tài liệu tham khảo 
1. Giáo trình ngôn ngữ C# 
2. Apress - Pro C# 2008 and the NET 3.5 Platform Fourth Edition 
3. Kỹ Thuật Lập trình C# 
4. Apress - Pro C# 2008 and the NET 3.5 Platform Fourth Edition 
5. Apress.Pro.LINQ.Language.Integrated.Query.in.C.Sharp.2008 
6. Apress.Pro ASP.NET 3.5 in C# 2008 
7. Lập trinh ASP.NET Tập 5.Quyển 3. Phạm Hữu Khang 

File đính kèm:

  • pdfGiáo trình Visual Studio 2008 - Microsoft ASP.NET 3.5.pdf
Tài liệu liên quan