Learn asp.net-Basics from scratch 1th/7 page _asp.net

Source: Internet
Author: User
Tags datetime servervariables
First day

Learning objectives:
--> -->
  • Learn the basics of label, TextBox, Button control usage
  • Mastering the connection string with the Stringbuider class
  • Understanding the environment variables of the server


    StringBuilder class:
    The namespaces are: System.Text.

    The StringBuilder class is an efficient class, and the method of Stringbuilder.append the connection string is very fast. Used to connect a large number of strings, the speed of the superiority will be reflected.

    Let me give you a few examples:
    --> -->In the head of CS or VB file Plus
    [C#]using System.Text;
    [VB]Imports System.Text

    [C#]StringBuilder sbFirst = new StringBuilder();
    sbFirst.Append(“这是第一个学ASPNET的例子</br>”);
    sbFirst.Append( “这个例子太简单</br>”);
    sbFirst.Append( “连三岁小陔都会做,我早知道了,嘿嘿。”);
    Response.Write(sbFirst.ToString());

    [VB]Dim sbFirst As StringBuilder = New StringBuilder()
    sbFirst.Append(“这是第一个学ASPNET的例子</br>”)
    sbFirst.Append( “这个例子太简单</br>”)
    sbFirst.Append( “连三岁小陔都会做,我早知道了,嘿嘿。”)
    Response.Write(sbFirst.ToString)

    Here's how to do it:
    Build a C # Web application project First, this nonsense I will say less.
    Put a Button control: ID is btnshowvariable
    Place a Label control: ID is labservervariable

    Click event to add button, following code
    --> --> --> -->private void Btnshowvariable_click (object sender, System.EventArgs e)
    --> --> --> -->{ --> --> --> --> --> -->
    --> --> --> --> --> -->Labservervariables.text = "";

    --> --> --> --> --> -->StringBuilder info = new StringBuilder ();

    --> --> --> --> --> -->foreach (Object Objvar in Request.ServerVariables)
    --> --> --> --> --> -->{
    --> --> --> --> --> --> --> -->Info. Append ("<span style=" font-size:9pt "" ");
    --> --> --> --> --> --> --> -->Info. Append (Objvar.tostring ());
    --> --> --> --> --> --> --> -->Info. Append ("= <font color=blue>");
    --> --> --> --> --> --> --> -->Info. Append (Request.servervariables[objvar.tostring ());
    --> --> --> --> --> --> --> -->Info. Append ("</font> </span> <br>");
    --> --> --> --> --> -->}

    --> --> --> --> --> -->Labservervariables.text = info. ToString ();
    --> --> --> -->}

    The results show:

    The pictures are as follows:


    So we can use it like this.
    Response.Write(Request.ServerVariables["REMOTE_ADDR"]); // IP地址
    Response.Write("<BR>");
    Response.Write(Request.ServerVariables["URL"]); // 网页的URL
     

    第二天

    学习目的:

  • Mastering the use of text boxes
  • First Contact Try...catch ... Grammar

    Today's content is very easy, with an example, enter the month and the day, to determine whether the input is correct

    The pictures are as follows:


    With a text box, ID is txtyear,txtmonth,txtdate;
    The code for the check button is:
    --> --> --> -->private void btnCheck_Click (object sender, System.EventArgs e)
    --> --> --> -->{
    --> --> --> --> --> -->int year, month, date;

    --> --> --> --> --> -->First, the input character is converted to an int type, if it is not a digital type,
    --> --> --> --> --> -->Will trigger an error
    --> --> --> --> --> -->Try
    --> --> --> --> --> -->{
    --> --> --> --> --> --> --> -->Year = Convert.ToInt32 (Txtyear.text);
    --> --> --> --> --> --> --> -->month = Convert.ToInt32 (Txtmonth.text);
    --> --> --> --> --> --> --> -->Date = Convert.ToInt32 (Txtdate.text);
    --> --> --> --> --> -->}
    --> --> --> --> --> -->Catch
    --> --> --> --> --> -->{
    --> --> --> --> --> --> --> -->Labcheckinfo.text = "Input is a non-numeric character. ";
    --> --> --> --> --> --> --> -->Return
    --> --> --> --> --> -->}

    --> --> --> --> --> -->If the first step is qualified, convert the input number to date format
    --> --> --> --> --> -->An error is raised if the date format is not met
    --> --> --> --> --> -->Try
    --> --> --> --> --> -->{
    --> --> --> --> --> --> --> -->DateTime dt = new DateTime (year, month, date);
    --> --> --> --> --> -->}
    --> --> --> --> --> -->Catch
    --> --> --> --> --> -->{
    --> --> --> --> --> --> --> -->Labcheckinfo.text = "The number entered does not conform to date format";
    --> --> --> --> --> --> --> -->Return
    --> --> --> --> --> -->}

    --> --> --> --> --> -->Labcheckinfo.text = "input correct";
    --> --> --> -->}


    Well, to add, about Stringbuider
    When dealing with strings, many people like + +, in fact, for string, once defined, you cannot change the
    The so-called + is just a new string variable and assigned
    So for the best way to use stringbuider Append, this will save a lot of resources for the server

    Current 1/7 page 1234567 Next read the full text
Related Article

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.