In those years, I was still learning asp.net (ii) Learning notes-Basic application

Source: Internet
Author: User

In those years, I was still studying asp.net (ii)

Those years, it was easy to see a video. But the lack of such a feeling is too slow, do not read quickly, so after some understanding, but also have to read a book, perhaps the book is not necessarily good, but the book will be said every place to say, well have a preliminary understanding. For example. NET platform, components and other knowledge introduction, so, those years began the asp.net aspects of further study.

First, learn the asp.net of preparation knowledge

As I have learned in previous years, I have to have a certain understanding of them before I begin:

1, the basic use of HTML language

2, Css+div Learning, holding the basic layout

3, JavaScript Foundation. In the early days, especially the operation of the DOM.

4, understand the use of the basic control asp.net

Second, start learning asp.net

1,. NET platform, such as the CLR (Common language Runtime), IL (Microsoft intermediate Language), JIT (Just-in-time compiler), CTS (common type System), CLS (Common Language Specification), and the. NET framework, and so on, of course. NET architecture, as shown in figure:

(This image comes from 51cto online)

2, asp.net page request response mechanism and HTTP protocol must be understood. HTTP is a stateless protocol, called Hypertext Transfer Protocol, which is transmitted as an HTML file between the browser and the server, and the Web server processes the user's request when the user requests a page in the form of a URL to the Web server. Return a Web page to the browser to display to the user, the process is completed after the browser and the Web server is not related to the, based on this process, ASP.net's request response is similar too, when the browser requests a Web page, the Web server processes the request, looks for the requested page, locates the file, and if the. aspx file, the Web server gives the request to the ASP.net CLR, compiles the execution, and after fetching the requested data from the database, generates a HTML file, which is sent to the browser. Here are some ideas:

Dynamic page: Simply put, the requested page is a file that does not exist on the server by reading the data generated from the database.

Static page: Simple is that the server has such a file, such as 404 pages

b/s: Refers to the way the browser and the server

C/s: Refers to the way the client and the server

Iii. the basis of asp.net

1, built-in objects, ASP.net has a lot of built-in objects, they played a considerable role, the following selected a few commonly used to say it.

Request object: Requested object, is an instance of the HttpRequest class, is automatically created, can be used to obtain user data submitted in the browser and some HTTP information, commonly used properties are: Cookies, Files, Form, Params, QueryString and so on, there are some methods, such as: MapPath, Savaas, etc.;

Response object: Response object, is an example of HttpResponse class, is also automatically created, there are many attributes (Cache, cookies, etc.) and methods (Redirect, write, etc.);

Session object: Conversation object, when a user opens a Web page, there is a session in the server that holds some information about the current user, and the session disappears when the user exits or closes the browser; often used to save user status, such as login, shopping cart, etc., using the form of a key/value pair, such as session["KEY"]=value;

Application object: Is a global, in the application of the State, from the beginning of the application run, until the end of the application, using the method with the session;

2, master page, this is a good thing, when surfing the internet, often found that some of the site's end is the same, or a section has not changed, each page has, then, this can be used to master pages to achieve. In ASP.net, a master page is a file that ends with. Master, which has a placeholder control that represents the place where the child page is displayed, with the following code:

Copy Code code as follows:

<%@ Master language= "C #" autoeventwireup= "true" codefile= "Show.master.cs" inherits= "Show"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<body>
<form id= "Form1" runat= "Server" >
<asp:contentplaceholder id= "ContentPlaceHolder1" runat= "Server" >
Child pages
</asp:ContentPlaceHolder>
</form>
</body>

3, custom user control, is an. ascx end of the file, which contains some HTML and asp.net server controls, of course, there is a code file, is a inherited from the System.Web.UI.UserControl class, we can make some common templates such as control, such as the repeater with a Spnetpager complete a paginated list control so that we can reuse the code, let's look at the example:
ASPX code:
Copy Code code as follows:

<%@ control language= "C #" autoeventwireup= "true" codefile= "WebUserControl.ascx.cs" inherits= "Images_" Webusercontrol "%>
<div>
<table style= "Background-color:buttonface; width:318px; " >
<tr style= "Text-align:left;" >
&LT;TD style= "background: #cccccc; font-size:22px; Color: #003399; Font-weight:bold;
width:1284px; " >
→ News Search
</td>
</tr>
<tr>
&LT;TD style= "WIDTH:1284PX; height:26px; " >
Author: <asp:textbox runat= "Server" id= "Textbox1" width= "214px" ></asp:TextBox>
</td>
</tr>
<tr>
&LT;TD style= "width:1284px" >
Title: <asp:textbox runat= "Server" id= "Textbox2" width= "234px" ></asp:TextBox>
</td>
</tr>
<tr>
&LT;TD style= "text-align:right; width:1284px; " >
<asp:button runat= "Server" id= "button" text= "Query" onclick= "Button_Click"/></td>
</tr>
</table>
</div>

CS Code:
Copy Code code as follows:

public partial class Images_WebUserControl:System.Web.UI.UserControl
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void Button_Click (object sender, EventArgs e)
{
String URL = "Authorname=" + Server.URLEncode (TextBox1.Text);
URL = + "&title=" + Server.URLEncode (TextBox2.Text);
Response.Redirect ("search.aspx?" + URL);
}
}


Iv. first asp.net procedure

1, open VS2010, a new ASP.net website, the following figure:

2, in this application add dal, BLL layer, in the solution right click-〉 Add-〉 New project, complete the following figure:

From the diagram can know, a project should have style, script, Master, and so on, of course, with VS2010 built a project with membership, I never used. or write yourself.

Summarize

Those years read a lot of books, and now may have forgotten some, this article to remember those reading days.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.