Asp. NET some of the common things

Source: Internet
Author: User
Tags script tag

Three-tier architecture naming:

Ui:user Interface (data display layer user interface)
Bll:business Logic Layer (business logic tier)
Dal:data Access Layer (data access tier)
Dao:data Access Object (data Access objects and data access layers one meaning)

Common code:

Clipboard.setdataobject (textbox1.selectedtext); copying data to the Pasteboard
This cannot call the static method, because this is a class property

To submit a form to ASP, be sure to add the name
Add an @ symbol to multiple lines of text
<asp:Button>, onclick is a server-side event, OnClientClick is a client click event
<input> (HTML page), the onclick is the client's Click event
Codeehind:aspx Control page What looks like, CS judgment business logic
Clientscript.registerstartupscript (GetType (), "Warning", "alert (' type Error! ') ", true);
When the page is loaded, the JavaScript script executes, the second parameter is the unique name in the page, and the last true is to automatically add the script tag

CS can invoke the controls in ASPX, the fields defined in the CS can also be accessed, functions, and complex C # code can be written, for, and so on
All C # code can be written in aspx (not recommended), <%%> contains statements in ASPX, which is C # code

-----RegisterStartupScript () and RegisterClientScriptBlock () server Register JS code

The RegisterStartupScript method places the <script> block at the end of the Web form to ensure that all HTML elements in the Web form are declared before the client script is executed.

RegisterClientScriptBlock () the script block sent by this method is at the beginning of the Web page, because this method does not require that the script block be placed behind all HTML elements.

Get Multiple values------form form

<input type= "text" name= "Txtdata"/>
<input type= "text" name= "Txtdata"/>

The first: This has a problem, when the user adds "," in the parameter, the comma will parse out multiple arrays

String[] Count = request.form["Txtdata"]. Split (', ');

The second kind: strongly recommend, solve the problem of user "," comma

Post submission with Request.Form.GetValues () method
Get Submit with Request.QueryString.GetValues () method

String[] Count = Request.Form.GetValues ("Txtdata"); The form is submitted by default by post

-----Traverse All TextBox controls

ASP. NET cannot traverse this directly like window. The controls are available because:
This. Controls only contain the page root level control, so that the secondary control does not traverse
A textbox is usually placed inside a form, traversing this. Controls will only access the form control without accessing the form's sub-contorl
The following is a full traversal of the page control tree using recursion

    private void Resettextbox (ControlCollection controls)    {        foreach (Control ctr in controls)        {            if (Ctr. Hascontrols ())            {                Resettextbox (Ctr. Controls);            }            If (Ctr is textbox)            {                (textbox) CTR). Text = "OK";}}    }        protected void Page_Load (object sender, EventArgs e)    {        //Call        Resettextbox (this. Controls);    }

Asp. NET some of the common things

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: 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.