Asp+ Chinese Course (ii)----asp+ Web Forms

Source: Internet
Author: User
Tags button type html form
asp+|web| Tutorial | Chinese ASP + Web Forms, a Microsoft term, according to its own words, the ASP + Web Forms page framework is an upgradeable NGWS runtime programming model that can dynamically generate Web pages on the server. Not too understood, actually, just like the HTML form, but it can be dynamically changed on the server side, and not like static HTML form as soon as the generation can not be changed, of course, with DHTML or remote script will also be able to do dynamic change, but after all, is not very convenient. So what is Web forms like? You've already met, remember the last time I gave that example, yes, that's a Web form, but since that example is full of static HTML, when you press the "Lookup" button, it's just a presentation, nothing happens, Now let's look at a truly web Forms that comes with an ad rotation control, a text entry box, a selection box, a button, and a text label, as follows.

File:Intro6.aspx

<link rel= "stylesheet" href= "Intro.css" >

<script language= "C #" runat=server>

void SubmitBtn_Click (Object sender, EventArgs e) {
Message.Text = "Hi" + Name.text + ", you selected:" + Category.selecteditem;
}

</script>

<body>

<center>

<form action= "intro6.aspx" method= "POST" runat= "Server" >

<asp:adrotator advertisementfile= "Ads.xml" bordercolor= "Black" borderwidth=1 runat= "Server"/>


Category: <asp: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>

OK, now let's take a concrete look at this asp+ program and ASP in the end what is different, first you may notice that the original ASP <%%> script delimiter disappeared, replaced by <script Language=...> Originally I most hate is this <%%>, especially in the HTML mixed use of time, it is not like a programming language, you have to see from such a program process flow, it is more difficult than heaven, now good. Of course this is not to say that you can not use <%%&gt, after all, it is forward compatible with ASP, but I still try to use 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 selected:" + Category.selecteditem;
}

</script>
Do you feel familiar with friends who have used C? Yes, this is an event handler written in C #, void SubmitBtn_Click (Object sender, EventArgs e), you might see it, void means that the function has no return value, the function has two parameters, the code has only one line, You may notice that the message, Name, and category in this line of code are not defined, so where do they come from? Look at the following code:
<form action= "intro6.aspx" method= "POST" runat= "Server" >

<asp:adrotator advertisementfile= "Ads.xml" bordercolor= "Black" borderwidth=1 runat= "Server"/>


Category: <asp: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>

Is this form completely different from the HTML form? First, all of the form items include the form itself followed by the runat=server, which means that this is the server-side control, as well as the traditional form of what <input type=text>, and so on, you look closely can see, The original text box becomes <asp:textbox&gt, the selection box changes to <asp:dropdownlist>, the selection box option changes to <asp:listitem&gt, and the submit button changes to <asp: Button&gt, this button corresponds to the control function of the SubmitBtn_Click function I mentioned just now, it is running on the server side. There is also a server-side control <asp:label id= "message" runat= "Server"/&gt, this asp:label is not the traditional form, it is a server-side text control, then there is a problem, If there is no such element in the traditional HTML, then how does asp+ receive it? You run this program, and then look at the HTML source code, you will find this line:
<input type= "hidden" name= "__viewstate" value= "a0z-1715863018__x" >
Yes, asp+ is passing through this hidden form.
There is a line of code under the <form> tag:
<asp:adrotator advertisementfile= "Ads.xml" bordercolor= "Black" borderwidth=1 runat= "Server"/>
Asp:adrotator, this is also a server-side control, see the name you know, advertising rotation, but relative to ASP, it is not using the built-in components, but as a server-side control, control it shows that 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 it and I won't explain it in detail.

OK, now run the program again, to appreciate the difference between it and the ASP, prepare the next content.


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.