Learn what the ASP.NET Appeal article has to activity you and how to use it by exploring the Form, QueryStrng, ServerVaribles, and Cookies collections.
In this chapter
The aboriginal two capacity looked at Alive Server Pages from a aerial level, discussed broadcast appliance development, and talked about the congenital ASP.NET languages.
In this chapter, you’ll see how to use the ASP.NET Appeal object. This important article runs on the server and you use methods, properties, and collections to affairs it. You’ll apprentice about the best frequently acclimated Appeal article and collections, and how to use them in your ASP.NET applications.
As you’ve already seen, VB, C#, and JScript central ASP.NET pages accredit the server to adapt agreeable that is apparent in the Web browser. This enables you to aggregate and affectation ethics such as the accepted date and time and the ethics of assorted HTTP variables. You can use this advice to accomplish decisions about what to accelerate the applicant browser, based on accepted quantitiessuch as with abstracts that’s based on the accepted date.
Altering HTML agreeable based on things such as date and time is dynamic, but not active. Visitors to a Web armpit that artlessly displays activating abstracts based on the date, time, or added variables are acquiescent receptors of information. Their alone ascribe to the advice aisle they chase is authentic by links they bang in the Web pages. So now it’s time to accede how to use ASP.NET to absolutely acquaint with the user.
Traditionally, Web browsers accept announced with servers through forms, area advice was beatific to a server CGI program. The affairs could again appraise this advice and aftermath a new HTML certificate on the fly to be beatific aback to the requesting client.
Alternatively, in some situations, the folio ability accept independent hyperlinks that included advice about the user’s selections. This is generally apparent in Web chase pages area beat on a articulation in the folio sends one or added ethics aback to the browser. The added advice is added to the URL to anatomy a concern string.
In both of these cases, ASP.NET enables you to aggregate advice that you can use in your code.
The advice stored in the Appeal article collections originates from the client, and is anesthetized to the server as allotment of the HTTP document request. The server decodes all this information, and makes it attainable to ASP.NET through the collections, which are allotment of the Request object’s interface.
Apart from the accustomed advice independent in the HTTP attack portions of the request, one way that the browser can accelerate specific advice to the server is with a form. This can be apparent in the apropos HTML folio with a <FORM> tag.
The afterward archetype asks users to admission their name and address. A Submit on sends the advice to addition folio (indicated by the activity attribute in the <FORM> tag), and the Reset on clears the form. The afterward cipher contains a anatomy with two altercation fields and Submit and Reset ons. On the Web site, the cipher has some formatting tagsthey accept been removed actuality for clarity.
This cipher is allotment of the folio that you can acquisition at http://www.UsingASP.net, selecting Affiliate Examples, Affiliate 3, again TextBox. You can additionally see the folio in Figure 3.1.
Figure 3.1 This anatomy enables users to admission two fields.
Notice that the <FORM> tag has an activity aspect that specifies a URL. The browser goes to this URL back the Submit on is clicked. The anatomy advice arrives as allotment of the HTTP header, and is easily attainable by the Appeal object. To get advice from a anatomy field, artlessly acknowledge a cord capricious into which the advice will be placed, and retrieve the cord abstracts with a Request.Form() adjustment call. The afterward cipher shows how to admission the cord independent in the Name acreage of the form:
The absolute cipher that gets the name and abode cord data, and displays it in the approachable document, can be apparent in the cipher fragment that follows. I’ll absorb added time in Affiliate 4 talking about how to achievement to the approachable document. For now, back you see an announcement such as
you will apperceive that it is demography the capacity of the strName variable and sending it out in the HTML document.
This cipher is allotment of the folio that is invoked by bushing out the anatomy apparent in Figure 3.1 and beat on the Submit on. You can see the rendered folio in Figure 3.2.
Figure 3.2 Here, you can see the abstracts acquired from Request.Form().
Many times, rather than activity users an editable altercation box, you charge to give them a account of agreed selections. A <SELECT> tag indicates the HTML assemble that does this. Aural the <SELECT> tag are the choices, themselves begin aural <OPTION> tags. The following cipher shows how to use <SELECT> tags to activity users choices. The afterward cipher differs from what is on the Web armpit because the formatting tags accept been removed actuality for clarity.
This cipher has two <SELECT> tags, anniversary with a altered name. One is Flavors and the added Containers. The folio that receives this anatomy uses these names to retrieve the anatomy contents.
This cipher is allotment of the folio that you can acquisition at http://www.UsingASP.net, selecting Affiliate Examples, Affiliate 3, again Select. You can see the folio in Figure 3.3.
Figure 3.3 Two Baddest altar activity users their choices.
Retrieving the abstracts from the called anatomy baddest items is the aforementioned as retrieving abstracts from a TextBox. Aloof acknowledge a cord variable, and get the abstracts application a Request.Form() adjustment call. The afterward cipher shows the cipher that gets the two selections and sends them out in the HTML document:
This cipher is allotment of the folio that is invoked by bushing out the anatomy apparent in Figure 3.3 and beat on the Submit on. You can see the rendered folio in Figure 3.4.
Figure 3.4 The abstracts acquired from Request. Form().
To activity users a best that’s either on or off, a analysis box is a good tool. An <INPUT TYPE=”CHECKBOX”> tag indicates a choice in HTML code. This tag has attributes with which you can specify its name and its value. Back they are called and submitted, they accommodate the value that’s defined in the Amount attribute.
For example, the afterward analysis box:
if selected, will accommodate the cord abstracts “ON” when retrieved with the Request.Form() adjustment as follows:
The afterward archetype offers users two categories, anniversary of which contains three choices. Because the choices are offered with analysis boxes, they can be accumulated in any way the user chooses. For example, the user can accomplish two choices in the aboriginal class of Chocolate and Vanilla, and one best in the second class of Cossack Cone. Radio ons, with which it is accessible to accomplish only one best in a category, are discussed later. The afterward cipher differs from what is on the Web armpit because the formatting tags accept been removed actuality for clarity.
This cipher is allotment of the folio that you can acquisition at http://www.UsingASP.net, selecting Affiliate Examples, Affiliate 3, again Analysis Boxes. You can see the folio in Figure 3.5.
Figure 3.5 Two sets of analysis boxes activity added adjustable choices.
The folio that receives and acts on the anatomy abstracts is apparent next. It examines the capacity of anniversary of the called anatomy fields (Chocolate, Vanilla, Strawberry, Cone, Cup, Cossack Cone) to see whether they accommodate the amount of “ON”. If they do, again the agnate analysis box was selected.
This cipher is allotment of the folio that is invoked by bushing out the anatomy in the archetype apparent in Figure 3.5 and beat on the Submit on. You can see the rendered folio in Figure 3.6.
Figure 3.6 Actuality are the after-effects of the user selection.
It’s generally all-important to actualize forms that accommodate assorted groups of accompanying information. For example, you can add two radio ons to the ice cream anatomy to accredit users to analyze their gender. The radio ons should have altered ethics so that you can analyze them back you use the Request.Form() adjustment to admission the data.
Take, for example, the afterward HTML code:
Now use the afterward cipher to retrieve the abstracts in the folio to which the submitted anatomy goes:
The strStringData capricious contains “Female” if the Female radio on was selected, and “Male” if the Male radio on was selected. Note that radio ons are aggregate calm by the Name attribute. Aural the accumulation one and alone one alternative can be made.
The afterward HTML cipher shows two groups of radio ons, anniversary of which offers three choices:
This cipher (which has had the formatting tags removed) is allotment of the folio that you can acquisition at http://www.UsingASP.net, selecting Affiliate Examples, Affiliate 3, again Radio Buttons. You can see the folio in Figure 3.7.
Figure 3.7 Radio ons activity mutually absolute sets of choices.
As apparent before, the Request.Form() adjustment is acclimated to retrieve the best for a radio on group. The aftereffect is a cord value, and contains whatever was defined by the Amount aspect of the called radio on.
The afterward cipher takes the anatomy in the archetype apparent in Figure 3.7 and outputs the cord abstracts to the HTML document:
This cipher is allotment of the folio that is invoked by bushing out the anatomy in the archetype apparent in Figure 3.7 and beat on the Submit on. You can see the rendered folio in Figure 3.8.
Figure 3.8 The radio on abstracts is acquired with Request.Form().
A TextArea is an HTML account that enables users to admission multiple curve of text. It’s advantageous for situations such as user comments, or for acceptance users to appeal information. The afterward cipher (which has had the formatting tags removed) shows a TextArea in a form:
This cipher is allotment of the folio that you can acquisition at http://www.UsingASP.net, selecting Affiliate Examples, Affiliate 3, again Altercation Area. You can see the folio in Figure 3.9.
Because users can blazon in aloof about annihilation they want, the altercation cord that you retrieve ability accommodate characters that, back achievement in an HTML document, don’t appearance up as you apprehend them to.
Figure 3.9 The TextArea account accepts assorted curve of text.
For example, if a user types in the < character, it doesn’t arise as such if you achievement it to the HTML document. That’s because this special appearance is interpreted as the alpha of a tag, and doesn’t arise as a accurate < character. The HTML cipher that renders it accurately to the user is <. It’s difficult to alter all these appropriate characters with their actual HTML equivalents if you intend on outputting strings to the HTML document. For this reason, ASP.NET provides a abettor adjustment named Server.HTMLEncode() that takes a cord and translates it to a string that renders accurately in an HTML document.
The antecedent archetype apparent in Figure 3.9 submits a TextArea, and the afterward cipher outputs it to the HTML certificate twice: the aboriginal time as is, the additional time with the advice of the Server.HTMLEncode() method. If the user types in a appropriate character, the aboriginal achievement does not account a actual rendering, admitting the additional does.
When a anatomy is submitted, it is absolutely retrieved as a collection. The Request.Form() method, as I’ve acclimated it so far, has taken a string altercation allegorical the name of the anatomy acreage that’s actuality retrieved.
There ability be occasions area you accept to enumerate all the anatomy fields. The best accepted use of this is back you’re debugging your ASP.NET applications and charge to appraise all anatomy acreage names and values.
You can enumerate through the absolute anatomy accumulating actual easily. The afterward cipher (which has had the formatting tags removed) is from a folio that submits bristles altered anatomy fields:
This cipher is allotment of the folio that you can acquisition at http://www.UsingASP.net, selecting Affiliate Examples, Affiliate 3, again Anatomy Collection. You can see the folio in Figure 3.10.
Figure 3.10 This anatomy has bristles ascribe fields.
Enumerating the anatomy accumulating is agnate to enumerating any other accumulating in ASP.NET. You can use a For/Next bend and enumerate through anniversary anatomy field, as the afterward cipher shows:
This cipher is allotment of the folio that is invoked by bushing out the anatomy apparent in the Figure 3.10 and beat on the Submit on. You can see the rendered folio in Figure 3.11.
Figure 3.11 You can see the after-effects of the anatomy enumeration.
How Will Registration Form In Asp Net Be In The Future | Registration Form In Asp Net – registration form in asp net
| Delightful for you to my personal website, in this occasion I’ll teach you in relation to registration form in asp net