China's largest web development resource website and technology community,
ASP + Web Forms, a new term of Microsoft, as its own words, the ASP + Web Forms page framework is an upgraded NGWS Runtime programming model that can dynamically generate web pages on the server. Isn't it easy to understand? In fact, it is plain, just like HTML form, but it can change dynamically on the server, not like the static HTML form, once the generation cannot be changed, of course, you can use DHTML or Remote Script to do it. Dynamic changes, but after all, it is not very convenient. So, what exactly does web forms look like? In fact, you have seen it, remember the example I gave last time, yes, that is a web forms, but because the example is full of static HTML, when you press the "LOOKUP" button Just a form, nothing happened. Let us see a real Web Forms in the real sense. It has an advertising rotation control, a text input box, a selection box, a button, and a text tag, the code is as follows.
file: intro6.aspx
<html>
<head>
<link rel = styleSheethref = intro.css>
</head>
<script Language = C# Runat = Server>
void submitbtn_click (Object Sender, eventArgs E) {{
Message.text = hi + name.text +, you select: + category.selectEdItem;
}
</script>
<body>
<Center>
<FORM ACTION = Intro6.aspx Method = Post Runat = Server>
<ASP: Adrotator AdvertisementFile = ads.xml BorderColor = Black BorderWidth = 1 Runat = Server/>
<h3> name: <asp: textbox id = name runat = server/>
category: <SSP: Dropdownlist ID = Category Runat = Server>
<ASP: ListITEM> PSYCHOLOGY </asp: listitem>
<ASP: ListITEM> Business </asp: listitem>
<ASP: listitem> popular_comp </asp: listitem>
</asp: DropdownList>
<ASP: Button Type = Submit Text = Lookup OnClick = SUBMITBTN_CLICK RUNAT = Server/>
<p>
<asp: label id = message runat = server/>
</form>
</center>
</body>
</html>
Well, now let's take a look at what is the difference between this ASP+ program is different from ASP. First of all, you may notice that the original < % %> script fixed line of ASP is gone. To be honest, what I hate most is this < % %>, especially when mixed in HTML, it is not like a programming language. You have to see the program process from such a program. It's difficult, it's okay now. Of course, this is not to say that you can't use < % %> now, after all, it is compatible with ASP, but I still try to use it as little as possible. Look at the following paragraph:
<script Language = C# Runat = Server>
void submitbtn_click (Object Sender, eventArgs E) {{
Message.text = hi + name.text +, you select: + category.selectEdItem;
}
</script>
Do friends who have used C feel familiar with? That's right, this is a event processing function written in C#, Void Submitbtn_Click (Object Sender, EventArgs E), you may understand at a glance. VOID means that the function does not return the value. The function has two parameters. One line, you may notice that MESSAGE, name, and category in this line of code are not defined, so where do they come from? Look at the code below:
<FORM ACTION = Intro6.aspx Method = Post Runat = Server>
<ASP: Adrotator AdvertisementFile = ads.xml BorderColor = Black BorderWidth = 1 Runat = Server/>
<h3> name: <asp: textbox id = name runat = server/>
category: <SSP: Dropdownlist ID = Category Runat = Server>
<ASP: ListITEM> PSYCHOLOGY </asp: listitem>
<ASP: ListITEM> Business </asp: listitem>
<ASP: listitem> popular_comp </asp: listitem>
</asp: DropdownList>
<ASP: Button Type = Submit Text = Lookup OnClick = SUBMITBTN_CLICK RUNAT = Server/>
<p>
<asp: label id = message runat = server/>
</form>
The writing of this form is completely different from the HTML form? First of all, all forms include runat = server behind the form itself. This sentence means that this is the server -side control item. In addition If you look closely, you can see that the original text box becomes <ASP: Textbox>, the selection box becomes <Asp: DropdownList>, the selection box option becomes <Asp: ListITEM>, and the Submit button becomes <ASP: Button>, the control function corresponding to this button is the submitbtn_clICK function I mentioned just now, which runs on the server. In addition, there is a server -side control. There is no such element in the traditional HTML, so how does ASP+receive? You can run this program, and then look at the HTML source code, you will find such a line:
<input type = hidden name = __ ViewState Value = A0Z-1715863018__X>
Yes, ASP+is passed through the form of this hidden form.
There is such a line of code under the <FORM> mark:
<ASP: Adrotator AdvertisementFile = ads.xml BorderColor = Black BorderWidth = 1 Runat = Server/>
ASP: Adrotator, this is also a server -side control, you know the name, the advertising rotation, but relative to ASP, it is not using built -in components, but as a server -side control. The control it shows this ADS.XML , The code is as follows:
file ads.xml:
<advertisements>
<ad>
<IMAGEURL> /quickstart/aspplus/images/banner1.gif </ImageUrl>
<targeturl> http://www.microsoft.com </targeturl>
<alternatetext> alt text </alternatetext>
<Keyword> Computers </keyword>
<Impressions> 80 </impressions>
</ad>
<ad>
<IMAGEURL> /quickstart/aspplus/images/banner2.gif </ImageUrl>
<targeturl> http://www.microsoft.com </targeturl>
<alternatetext> alt text </alternatetext>
<Keyword> Computers </keyword>
<Impressions> 80 </impressions>
</ad>
<ad>
<IMAGEURL> /quickstart/aspplus/images/Banner3.gif </ImageUrl>
<targeturl> http://www.microsoft.com </targeturl>
<alternatetext> alt text </alternatetext>
<Keyword> Computers </keyword>
<Impressions> 80 </impressions>
</ad>
</advertisements>
Take a look at myself, I will not explain in detail.
Well, run this program again now, and experience the difference between it and ASP and prepare the next content.