Asp.net--web server-side controls and HTML controls

Source: Internet
Author: User

Today, we summarize some relevant concepts and knowledge.

Before whether it is to do a stand-alone WinForm or CS WinForm feel, less than two years down feeling can still, although the API has a lot, but still more familiar with the Windows message mechanism based programming, but now the network hardware facilities Update fast, BS development advantage of the big, However, the technical aspects need to widen a lot, javascript,css,html need to understand, in addition to WebForm, for today's mainstream MVC is the need to learn.

Concept:

ASP. NET control server-side control to respond to server-side events
HTML Control Client Control--> Respond to client Events
HTML client events are not submitted to the server side, more than say click button, change the text color, etc., just pin the user machine itself, is not sending packets to the remote servers
When the ASP. NET button is clicked, it will be sent to the server as post or get, database operation and so on, the page will be refreshed after submission.
But Ajax technology makes the client control send a request to WebService

Phenomenon Gets the content that the user enters into the text box :

Server-side control: string S=textbox1.text;

HTML control: String s=request.querystring["Text1"]; Text1 as parameter

Other:

<input type= "text" name= "name" ><input type= "button" value= "OK" >
Defines a variable obtained by Request.getparameter ("name"), where name is the label name
In addition to JavaScript, you can
First add an ID to the label such as <input type= "text" name= "name" id= "Name" >
Again through the document.getElementById ("name"). Value gets the values in the label
===========================================================

There are two ways to get the contents of a text box:

Assume the following text box:

<input type= "text" value= "" id= "text" >

1, native JS Gets the value of the text box:

document.getElementById ("text"). Value//text as the ID of the text box

2. jquery Gets the value of the text box:

$ ("#text"). Val ()
============================================================

Web server-side controls and HTML control relationships

The HTML page extension is. htm or. html. If the browser requests an HTML page from the server and the server does not make any changes, it will send the page to the browser.
The extension of the ASP. NET page is. aspx. If the browser requests an ASP. NET page, the server will first process the executable code in the page before sending the result back to the browser.
The final browser will still be HTML output, and the server control's page access speed is much slower than the HTML. ASP. NET to the page over and over again to refresh the form of HTML, which determines that his mechanism is very slow. And the more The pursuit of programmer-friendly, powerful, then the more serious the performance problem.

Bottom line: The server control is encapsulated with HTML controls. server controls maintain state through ViewState, and HTML does not, and can be used directly with HTML controls if there is no interaction.

Server-side controls will have a runat= "Server" property,
So that it can be modified in the background,
That is, in the CS code can modify the settings.
You can test to put an HTML control in the CS code that does not reference the name of the control
Then the HTML control plus runat= "Server" can reference the control in the CS code.
Essentially ASP. Returns to the foreground or HTML control after parsing a server control
Build a page, put a asp:textbox up.
Then run the page and view the page source file
You will find that the server control that you put on becomes the HTML inupt type= "button"

<asp:button width="7%"  id="btnupdate " runat="  server" text="Update" cssclass="Trcss_ TOT1 "onclick="btnupdate_click "/>

By the way, ViewState:

Because the HTTP connection is stateless, each page request cannot log information from the last requested page.
Then to save the last request on the page control of the value, that is, the page refresh, fill in the value of the same, for example, in the textbox filled with a ' a ', the page after the refresh or ' a ',. NET Framework to implement this mechanism, the ViewState view state is used to hold the values of these controls,
So where does the value of all the controls exist? You can run the program, and then view the source file in the page, you can see a input type= "hidden" name= "__viewstate" label, this is called "view", it is serialized through the server, The server then deserializes the values of the hidden fields and then assigns the values to the controls again, so that the page refreshes and records the values of all the controls at the time of the last request. The server control will be saved by default ViewState has a property (EnableViewState) can be set, set to Flase will not save, the page refreshed, the value is gone, Can do a test put a TextBox set EnableViewState to False, and then enter a value, and then use the button to refresh the page, then the textbox will be empty, because there is no view state record to the last input value.

Server-side control &html the use of controls
First of all: the server-side control is only Microsoft to facilitate some of the developers to encapsulate some HTML control, so the root of the server-side control from the HTML control, but on the basis of this control to add some of the encapsulated Css\js and open some other people set up the interface just.
So it is absolutely impossible to say that HTML control trends are canceled. It's canceled. There is no meaning to the existence of the web. To say that the cancellation trend is also a server-side control.
The development trend of server-side control, from these years, the exclusion of more and more people, why?
1. Setting the style is very inconvenient (not to say that you can't set the style), but not directly.
2. Most ordinary people do not know how to optimize for server-side controls----such as whether to cancel ViewState, whether it is necessary to postback the control, in short, often see these people do the Web page source code than ordinary HTML control developers have at least one generation of garbage code. Not only performance is not good upgrade, also verify the impact of SEO optimization.
3. It is inconvenient to write some of the corresponding JavaScript. Every time you want to get a real server-side ID, if you want to write JavaScript in the JS file, it is a bad Hao, you have to work with a non-ID or other way to declare. Tedious
4. From Microsoft's current technology trends, the gradual abandonment of server-side control development is also a mainstream. Of course choose what or depends on your project to decide, some development companies are born to speed, drag server control rapid development is nothing to say bad and good.

Recommend this relevant reference and excellent blog: http://blog.csdn.net/lxfzgg/article/details/8467232

Asp.net--web server-side controls and HTML controls

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.