Author: Blue whale Source: 5D Multimedia
Learning ASPNET is different from ASP. This difference is not a language, but the difference between thinking. The ASP is purely-oriented, while the ASPNET is completely directed. This difference allows us to have a large difference from ASP on programming structural design.
Tony said nonsense, now I am also starting with you. I use C #, in fact, friends who use VB.NET should also be able to understand, I will explain some differences in different.
first day
Learning Purpose: Master the most basic Label, TextBox, button control usage Master the StringBuider class connection string comprehensively understand the environment variables of the server
StringBuilder class: The namespace is: System.Text.
The StringBuilder class is an efficient class, and the StringBuilder.Append connection string is very fast. Used to connect a large number of strings, the superiority of its speed will be embodied.
First mention a few examples: Plus on the head of the CS or VB file
[C #] Using system.text; [vb] imports system.text [c #] stringbuilder sbfirst = new stringbuilder (); sbfirst.Append ("This is the first example of the example of ASPNET"); sbfirst.Append ("This example is too simple "); SBFirst.Append ("I will do it in three years old, I know, hehe."); Response.write (sbfirst.toString ()); [vb] DIM SBFirst As Stringbuilder = new stringbuilder () sbfirst.Append ("This is the first example of ASPNET ") sbfirst.append ("This example is too simple ") sbfirst.Append ("even Three years old will do, I know, hehe. ") Response.write (sbfirst.toString)
Let's be a topic: first build a C # web application project, I will say less this waste. Put a Button control: ID is a Label control for btnshowvariable: ID is labservervariable
Add Button's click event, as follows:
private void btnShowVariable_Click (object sender, System.EventArgs e) {labServerVariables.Text = ""; StringBuilder info = new StringBuilder (); foreach (object objVar in Request.ServerVariables) {info.Append ( " "); info.append (" = "; info.append (request.servervariables [objvar.tostring ()]); Info.append (" font> span>
");} labservervariables.text = info.tottring ();} The result is as follows:
This way we can use it:
Response.write (Request.SerVariables ["remote_addr"]); // IP address response.write ("
"); response.write (Request.ServerVariables ["URL"]); // URL of the web page
the next day
Learning Purpose: Master the usage of text boxes first contact TRY ... CATCH ... syntax
Today's content is very easy, use an example, enter the annual day, and determine if the input is correct.
Use a text box, ID is TXTYEAR, TXTMONTH, TXTDATE; the code of the inspection button is:
Private void btncheck_click (object sender, system.eventargs e) {int year, month, date; // first convert the input character to int type, if not digital, // will trigger error try {year = convert.Toint32 ( TXTYEAR.TEXT); MONTH = Convert.TOINT32 (TXTMONTH.TEXT); DATE = Convert.TOINT32 (TXTDATE.TEXT);} Catch {LabCheckInfo.text = "Enter non-numeric characters."; return;} // If One-step inspection is passed, transform the input numbers into date format // If the date format is not compliant, it is not compliant. Not in compliance with the date format "; return; labcheckinfo.text =" Input correct ";} On the third day
Learning purpose:
Master the usage of the drop-down list box and understand the AutoPostBack property;
Understand the ISPOSKBACK and Usage;
The method of adding the DataTable to increase the column, line, and the drop-down list box.
Today's content is slightly more, and there are some basic uses, such as IsPostback and DataTable.
Knowledge point: ispostback: The value is false between the page OnLoad, and when the server is passed back, the value becomes true. When the Button or ImageButton and other in the page are triggered, it will return the form to the server, and the ONLOAD event will be caused when it returns. In order to save server resources, some load is required once, without having to happen multiple times after passing, you can use! Isposkback as a condition, then the page will not happen after the page is loaded. This attribute can help you improve the performance of the program. Dataable: That is, the most common class in the .NET program, especially database development, programs without such classes are unimaginable.
First make a small program to practice hands, very simple, just a drop menu, name DLstWeb. Open the following dialog in the ITMES option of the property, add each:
The code in the ASPX is:
private void dlstWeb_SelectedIndexChanged (object sender, System.EventArgs e) {Response.Write ( "