Reading books generally looks at directories first, and habitually starts from Chapter 3, except for the books andCodeOther Chinese technical books that have been written by myself or translated are all clear. In the first two chapters, add n basics, no matter what you are talking about, reading a book for the first time has become a habit since Chapter 3.
Like other books that explain Asp.net, Chapter 3 begins with the control. However, after reading this chapter, the author's ideas about the problem and the translator's translation have indeed confused me a lot, after reading the subsequent chapters, I feel that the author is too nervous to introduce Asp.net to a friend who has never been familiar with web development.
FromAnother AngleAlso, let's take a look at several controls in Asp.net: Asp.net Server Control, HTML server control, and HTML control.
Asp.net server control is the most basic Asp.net component. This book also uses six chapters to introduce the knowledge of commonly used controls, 2.0 new controls, and control development. How can we understand the relationship between two types of control in HTML and Asp.net Server Control? The simplest thing is to look at it from the highest point of view-to see what it is when they are finally presented to the client browser. We use the followingSimple scenarioLet's take a look:
Suppose we want the user to enter the user name, click the submit button, the server obtains the user's age from the server based on the user name, and then displays it on the page. Drag and Drop a textbox and a button, and place and configure a verification control. When we use the verification control, Asp.net will display * to the page using the span tag and a bunch of control style attributes, and the running mechanism is controlled by scripts, these scripts automatically send the code suitable for the browser to the client based on the user's browser.
At this time, we run this page and check its source code. It is easy to see that Asp.net server button control is an HTML input control with the type of submit. At this time, we place another HTML control button control, add its properties to runat = "server", run it, and then seeSource code, You can see that he is render into an HTML input control with the type of button. At this time, clicking either of the two controls will result in Page Submission (if the verification control is verified). As the Asp.net Server Control of the submit, it is easy to understand why the submission is triggered, what about html Server Control? This is because the script it calls contains _ dopostback ('button2', ''), and the _ dopostback () function in the page makes the page submitted. After the verification control is added, both of them need to perform data check before submission. They use scripts to verify whether page data can be submitted, but the methods are completely different:
< Input
Type= "Submit" Name = "Button1" Value = "Button"
Onclick = "Javascript: webform_dopostbackwithoptions (New webform_postbackoptions (& quot; button1 & quot;, & quot;, true, & quot;, & quot ;, false, false ))" ID = "Button1" />
input language =" JavaScript " onclick =" If (typeof (page_clientvalidate) = 'function') page_clientvalidate (''); _ dopostback ('button2','') " name =" button2 " type =" button " id =" button2 " value =" button " />
<SpanID= "Requiredfieldvalidator1"Style= "Color: red; visibility: hidden ;">Please enter your Username</Span>
Now we can see that the script for embedding the resource file is used like this, but if you want to know what these methods have done, you can use tools such as fiddler, httpwatch, or firebug, however, the quickest way is to enter the address bar of the browserJavascript: js_method_name. For example, javascript: webform_dopostbackwitexceptions can be used to view the content of this method.
Well, starting with the results, we can see the results and the client page Execution Process in depth. Then we may jump out again,ReviewIn this process, you need to enter the username of the user, and then retrieve the corresponding age from the database based on the value and display it on the page, the whole process is to submit the user data name, the server obtains the user name, and then returns the age to the client. Aside from HTTP information, only username and age should be passed back and forth. But let's see if we have transferred too much useless data?
Then weSimplify the process: We use HTML control to place an input control whose type is button and text, when a button is clicked, execute a JavaScript function to check whether there are any characters in the text and then send it to the server. For example, by calling a web service in the server segment, after verifying the data, the Web Service extracts the data from the database and returns it to the client. After receiving the data, the script displays it on the page.
YesNote:Generally, most browsers can modify the value of page elements through the address bar. Therefore, it is necessary to make judgments on the server.
At this time, we can see that the two processes are totally different, but they are also very different in terms of development efficiency and post-maintenance. If the Asp.net server control is not used properly, the consequence is a disaster.
After reading this chapter, I will read the "Bricks" and remove runat = "server" in <asp: button.../> to see what the results are? Think about whether the word "control" can be more clearly recognized by the browser's explanation of HTML?