Tài liệu Tài liệu đào tạo ASP.NET pdf

54 468 3
Tài liệu Tài liệu đào tạo ASP.NET pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

CÔNG TY CỔ PHẦN PHÁT TRIỂN ĐẦU TƯ CÔNG NGHỆ FPT Công ty Hệ thống thông tin FPT TÀI LIỆU ĐÀO TẠO ASP.NET Tài liệu đào tạo asp.net v1.0 Hà nội, 09/2009 Mục lục I. Nền tảng lập trình web 1 Web Programming 2 II. ASP.NET .3 III. Using JavaScript Along with ASP.NET .15 III.1 Adding JavaScript to a Server Control 15 III.2 Performing a Simple Button-rollover 17 III.3 Setting Control Focus 18 III.4 Changing the Control Focus Dynamically 18 III.5 Using Larger JavaScript Functions .18 III.5.1 RegisterStartupScript Method 19 III.5.2 RegisterClientScriptBlock Method 20 III.5.3 The Difference Between RegisterStartupScript and RegisterClientScriptBlock 22 III.6 Keeping JavaScript in a Separate File (.js) 22 IV. Data Access: .23 SqlDataReader 23 SqlParameter .24 Close Connection .24 When good connections go bad 24 IIS 6 on Windows 2003 Server .25 V. Microsoft Data Access Application Block 27 V.1 Introduction: 27 V.2 Using Microsoft .net Data Access Application Block: 27 V.3 Accessing data without Data Access Application Block: 27 V.4 Retrieving Multiple Rows using SqlDataReader and Data Access Application Block: 27 V.5 Retrieving Multiple Rows using DataSet: 27 V.6 Retrieving a Single Row .27 2/55 Tài liệu đào tạo asp.net v1.0 V.6.1 Stored Proc: 27 V.7 Explanation of the code: .27 V.8 Retrieving XML Data: 27 V.9 Explanation of the Code: .27 VI. Directory and File Access .28 3/55 I. Nền tảng lập trình web Tài liệu đào tạo asp.net v1.0 Web Programming Modern Information Processing 2/55 Tài liệu đào tạo asp.net v1.0 Components of a Web Page II. ASP.NET ASP.NET Environment • ASP.NET has a rich set of objects to work with in an object-oriented and compiled programming environment • The programming environment supports more than 25 .NET languages, including built-in support for VB.NET, C#, and JScript.NET • .Net frame work 3/55 Tài liệu đào tạo asp.net v1.0 Page Structure Server Controls and Script Processing Form Submission The <form> Control: Web form controls are enclosed within a single <form> tag in the format shown below: <form runat="server"> .server controls and HTML code </form> Input Controls Web Form Control Equivalent HTML Tag <asp:Textbox/> <input type="text"> <textarea> .</textarea> <asp:RadioButton/> <asp:RadioButtonList> <input type="radio"> <asp:CheckBox/> <input type="checkbox"> 4/55 Tài liệu đào tạo asp.net v1.0 <asp:CheckBoxList> <asp:DropDownList/> <asp:ListBox> <select> .</select> CheckBoxList: public static string LoadCheckBoxList(CheckBoxList pCtrl,string pCommandText,string pValueField,string pTextField) { try { DataTable dt = new DataTable(); dt = GetDataTable(pCommandText); pCtrl.DataSource = dt; pCtrl.DataValueField = pValueField; pCtrl.DataTextField = pTextField; pCtrl.DataBind(); return ""; } catch(Exception ex) { return ex.Message; } } DropDownListControl: public static string BindDropDownListControl(DropDownList pCtrl,string pCommandText,string pValueField,string pTextField,bool pRowBlank) { try { DataTable dt=clsCommon.GetDataTable(pCommandText); pCtrl.DataSource=dt; pCtrl.DataTextField=pTextField; pCtrl.DataValueField=pValueField; pCtrl.DataBind(); pCtrl.Items.Insert(0,""); dt=null; 5/55 Tài liệu đào tạo asp.net v1.0 return ""; } catch(Exception ex) { return ex.Message; } } Output Controls Web Form Control Equivalent HTML Tag <asp:Label/> <span> .</span> <asp:Panel> <div> .</div> <asp:Table> <table> <asp:Image/> <img> Script Activation Controls Scripts can be activated by user events surrounding the Web page. Certain controls, then, are provided for trapping those events and taking action on them. The primary example of a script activation control is the <asp:Button> control. The user clicks the button; a subroutine is called in response. Script activation controls come packaged with event handlers to trap and take action on user events. The most common event is a mouse click on a button; the most common event handler is the OnClick handler associated with the button. For example, the following button definition, <asp:Button Text="Submit" onClick="Display_Output" runat="server"/> displays a button control with the label "Submit." It includes an OnClick event handler which makes the button sensitive to a mouse click. When the button is clicked, the event handler calls the Display_Output subprogram and that script is run. There are a number of server controls designed for the purpose of trapping user events and responding to them. The following controls are discussed in these tutorials: Web Form Control Equivalent HTML Tag <asp:Button/> <input type="button"> <asp:ImageButton/> <input type="image"> <asp:LinkButton/> <input type="button"> <asp:HyperLink/> <a href> Script Activation Events 6/55 Tài liệu đào tạo asp.net v1.0 Scripts can be run in response to Web page events as well as to user events. A key page event is the load event, which occurs when the page is first retrieved by the server in response to a URL request. At the same time, there are two conditions under which a page is loaded. On the one hand, it can be an initial page-load event -- the first time the page is retrieved in response to a URL request; or, it can be a post-back event -- a reloading of the same page on form submission. These two page-load events can be, and often are, programmed separately. <SCRIPT runat="server"> Sub Page_Load() If Not Page.IsPostBack Then --do this on initial page load End If --do this on every page load End Sub </SCRIPT> In this example the Page_Load subroutine (this subprogram name is required) is run every time the page is loaded. It is run when the page is initially accessed through a URL request; it is run when the user clicks a control to call a subroutine. However, that portion of the script enclosed within the If Not Page.IsPostBack condition is run only the first time the page is loaded, not when responding to a user event to reload the page, say when a button is clicked to submit a form. Many of the scripts in these tutorials differentiate between initial page load and post-back load events. Information Display Controls There are three special controls that have no equivalence among standard form tags. These controls are unique to ASP.NET and are designed to ease and to automate the display of complex information. Most often these controls are used to display tables of data from databases. They are designed so that minimal coding is required to extract information from those tables and format it for display. We'll leave discussion of these controls for later. Web Form Control Equivalent HTML Tag <asp:Repeater> (none) <asp:DataGrid> (none) <asp:DataList> (none) The Page ViewState This repopulation of controls with submitted values occurs through the page's View State. The View State is the status of the page when it is submitted to the server. ASP.NET maintains this status through a hidden field that it places on pages containing form controls. If you take a look at the browser's source listing you will see this hidden field, named "__VIEWSTATE", and its encoded value that looks something like the following: <form name="_ctl0" method="post" action="page.aspx" id="_ctl0"> <input type="hidden" name="__VIEWSTATE" value="dDwtMTI3OTMzNDM4NDs7PqIp6fnWsFyownq1sZyOLgKFOBwj" /> . </form> Maintaining Variables on PostBack 7/55 [...]... an ASP.NET page using the following code: Visual C# NET Page.RegisterClientScriptBlock("MyScript", ""); Once the js file is imported into the ASP.NET page, any of the JavaScript functions can be called as before This is a great way to manage JavaScript functions and keep them separate from the other logic 22/55 Tài liệu đào tạo asp.net v1.0 of ASP.NET. .. 22222 Adobe Illustrator 249.95 5 1,249.75 On Order 44444 Microsoft Office XP 699.99 9 6,299.91 On Order Tài liệu đào tạo asp.net v1.0 III Using JavaScript Along with ASP.NET III.1 Adding JavaScript to a Server Control It is quite easy to add JavaScript to a specific server control that resides on an ASP.NET page Let's take a look at the button server control as an example If you drag and drop a Button... the database name 24/55 Tài liệu đào tạo asp.net v1.0 IIS 6 on Windows 2003 Server I know this will work on IIS 6 with Windows 2003 Server because I have done it and that is currently the only OS with IIS 6 On IIS 6 the ASP.NET process runs under the account 'NT AUTHORITY\NETWORK SERVICE' osql -E -S %SERVER%\%INSTANCE% -Q "sp_grantlogin 'NT AUTHORITY\NETWORK SERVICE'" Now our ASP.NET application will... possible to have multiple forms in HTML) This was an easy way to add some JavaScript to work with an ASP.NET Web server control Though, we could have also just as easily added a JavaScript command to the button itself as shown here in the following partial code example: Visual C# NET 16/55 Tài liệu đào tạo asp.net v1.0 void Page_Load(object sender, EventArgs... function AlertHello() { alert('Hello'); } Working with this ASP.NET page, notice that there is one JavaScript function that was placed at the bottom of the page before the close of the form () 19/55 Tài liệu đào tạo asp.net v1.0 When working with the RegisterStartupScript method, the constructor asks for two parameters—the first being... id="ProductsTable" runat="server"> No. 12/55 Tài liệu đào tạo asp.net v1.0 Name Price Qty. . Tài liệu đào tạo asp. net v1.0 Web Programming Modern Information Processing 2/55 Tài liệu đào tạo asp. net v1.0 Components of a Web Page II. ASP. NET ASP. NET. ĐẦU TƯ CÔNG NGHỆ FPT Công ty Hệ thống thông tin FPT TÀI LIỆU ĐÀO TẠO ASP. NET Tài liệu đào tạo asp. net v1.0 Hà nội, 09/2009 Mục lục I. Nền tảng lập trình

Ngày đăng: 22/12/2013, 23:16

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan