asp+ Chinese Tutorial (iii)--server-side control (i)

Source: Internet
Author: User
Tags comparison valid
asp+| Server | tutorials | control | Chinese last talk about ASP + server-side control content, now to tell you in detail. ASP + server-side control is the new concept proposed by Microsoft, its implementation is based on Microsoft. NET Framework, it is actually a special kind of HTML element, the server side and it is interactive relationship, after generating these elements not only can accept their values, but also can dynamically control them, to complete some very cool features. All of the 28 server-side controls and their specific uses that are currently supported by all ASP + are listed below.

1, Adrotator: Advertising rotation server-side control, its specific behavior is defined in the specified XML file, as follows:

<Advertisements>
<Ad>
<ImageUrl>/quickstart/aspplus/images/banner1.gif</ImageUrl>
<NavigateUrl>http://www.microsoft.com</NavigateUrl>
<AlternateText>Microsoft.com</AlternateText>
<Keyword>Computers</Keyword>
<Impressions>80</Impressions>
</Ad>
</Advertisements>

The meaning of the attribute:
<imageurl&gt: The absolute or relative path of the picture to be displayed.
&LT;NAVIGATEURL&GT: Click on the URL that the image points to, and if it is blank, the picture cannot be clicked.
<alternatetext&gt: The mouse moves to the hint message displayed on the picture.
<keyword&gt: Specifies the filter keyword for the ad page.
<impressions&gt: The display percentage of the advertisement, the higher the number, the more times it appears.

2, Button: This good understanding, similar to the traditional form of button, but the use of a slightly different, the specific use of my ominous.

3, Calendar: A very convenient calendaring control, so that you do not have to use JavaScript to make up, but also to calculate a leap year or something, to worry about how annoying, look at the following example:


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

void Date_selected (Object s, EventArgs e) {
Label1.Text = "Selected date is:" + Calendar1.SelectedDate.ToShortDateString ();
}

</script>


<body>


<form runat=server>

<asp:calendar id=calendar1 onselectionchanged= "date_selected" runat= "Server"/>

<p>

<asp:label id=label1 runat= "Server"/>

</form>

</body>

This control comes with a property selectionmode, and its specific attribute values are as follows:
Day: You can choose any single date.
DayWeek: You can choose one day or one weeks.
DayWeekMonth: You can choose one day or one weeks or one months.
None: Cannot select date.


4, CheckBox: check box, there is nothing to say, but there is a difference, that is, if its AutoPostBack property is set to True, click it can be submitted to the server side.

5, CheckBoxList: As the name suggests, a group of optional check box list, it has two important attributes, RepeatLayout and RepeatDirection, control the layout of the list, set to table then the list to the bottom, if set into flow, There is no table, repeatdirection default is vertical, vertical arrangement, if set to horizontally, then arrange horizontally.

6, CompareValidator: Two server-side control of the comparison. It has three important attributes that cannot be missing: ControlToValidate, ControlToCompare decides to compare those controls, operator determines the way of comparison, is equal to, not equal to, greater than, less than. The concrete implementation looks at the following example:

Comparevalidator1.aspx

<%@ Page Clienttarget=downlevel%>

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

void Button1_onsubmit (Object sender, EventArgs e) {

if (page.isvalid) {
Lbloutput.text = "result:valid!";
}
else {
Lbloutput.text = "Result:not valid!";
}
}

void Lstoperator_selectedindexchanged (Object sender, EventArgs e) {

Comp1. Operator = (validationcompareoperator) lstoperator.selectedindex;
Comp1. Validate ();
}

</script>

<body>

<p>type a value in each textbox, select a comparison operator, then click ' Validate ' to test.</p>

<form runat=server>

<table bgcolor= "#eeeeee" cellpadding=10>
&LT;TR valign= "Top" >
<td>
<asp:textbox Selected id= "Txtcomp" runat= "Server" ></asp:TextBox>
</td>
<td>

<asp:listbox id= "Lstoperator" onselectedindexchanged= "lstoperator_selectedindexchanged" runat= "Server" >
<asp:listitem Selected value= "Equal" >Equal</asp:ListItem>
<asp:listitem value= "NotEqual" >NotEqual</asp:ListItem>
<asp:listitem value= "GreaterThan" >GreaterThan</asp:ListItem>
<asp:listitem value= "Greaterthanequal" >GreaterThanEqual</asp:ListItem>
<asp:listitem value= "LessThan" >LessThan</asp:ListItem>
<asp:listitem value= "Lessthanequal" >LessThanEqual</asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:textbox id= "Txtcompto" runat= "Server" ></asp:TextBox><p>
<asp:button runat=server text= "Validate" id= "Button1" onclick= "Button1_onsubmit"/>
</td>
</tr>
</table>

<asp:comparevalidator id= "Comp1" controltovalidate= "txtcomp" ControlToCompare = "Txtcompto" "Type=" String "runat=" Server "/>

<br>

<asp:label id= "Lbloutput" font-name= "Verdana" font-size= "10pt" runat= "Server"/>

</form>

</body>


7, CustomValidator: Custom comparison, the role is to be able to do the basic comparison can not complete the comparison operation. This comparison can be run on the server side, or it can run on the client, such as with VBScript or JavaScript. The usage is very simple, see example.

Customvalidator1.aspx

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

void Validatebtn_onclick (object sender, EventArgs e) {

if (page.isvalid) {
Lbloutput.text = "Page is valid!";
}
else {
Lbloutput.text = "Page is not valid!:-(";
}
}

BOOL ServerValidate (object source, string value) {

int num = int32.fromstring (value);

if (num%2 = 0)
return true;
Else
return false;
}

</script>

<body>


<form runat= "Server" >

<asp:label id=lbloutput runat= "Server"
Text= "Enter An even number:"
Font-name= "Verdana"
Font-size= "10pt"/><br>

<p>

<asp:textbox id=text1 runat= "Server"/>



<asp:customvalidator id= "CustomValidator1" runat= "Server"
Controltovalidate= "Text1"
onservervalidationfunction= "ServerValidate"
Display= "Static"
Font-name= "Verdana" font-size= "10pt" >
Not a even number!
</asp:CustomValidator>

<p>

<asp:button text= "Validate" onclick= "Validatebtn_onclick" runat= "Server"/>

</form>

</body>


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.