Asp. NET Learning article (4)--server-side controls

Source: Internet
Author: User
Asp.net| Server | control One, validation controls

There are several validation controls:

RequiredFieldValidator, must fill in the contents
CompareValidator, comparing the values of a constant or another control
RangeValidator, scope validation
RegularExpressionValidator, compare with one mode, use for email, ZIP code verification
CustomValidator, customizing conditional validation
ValidationSummary, displays the validation error message digest, and if validation fails, the Page Object IsValid property is set to False and an error message is automatically displayed.


Validation controls are automatically generated by the client-side validation scripts, or they are validated on the server after they are submitted back to the server. Validation controls are valid only for specific properties of some controls:
HtmlInputText value
HtmlTextArea value
HtmlSelect value
HtmlInputFile value
TextBox Text
ListBox SelectedItem
DropDownList SelectedItem
RadioButtonList SelectedItem
。 RequiredFieldValidator
。 CompareValidator

Property:

ControlToValidate-Validated controls
Value of ControlToCompare comparison
Operator Comparison method

Cases:
<asp:comparevalidator id= "Compare" runat= "Server"
Controltovalidate= "Password"
ControlToCompare = "Confirmpwd"
Operator = "equal"
>
</asp:CompareValidator>
。 RangeValidator

Property:

ControlToValidate-Validated controls
Miniumcontrol Minimum value
Maxiumcontrol Max Value

Cases:

<asp:rangevalidator id= "Range" runat= "Server"
Controltovalidate= "Age"
Miniumcontrol = 15
Maxiumcontrol = 100
>
</asp:RangeValidator>
。 RegularExpressionValidator

Property:

ControlToValidate-Validated controls
ValidationExpression matching pattern, with regular expressions (one connection)

Cases:

<asp:regularexpressionvalidator id= "Regular1" runat= "Server"
Controltovalidate= "TextBox1"
validationexpression= "^\d{5}$"
display= "Static"
Font-size= "10pt" >
Zip code must be 5 digits
</asp:RegularExpressionValidator>
。 CustomValidator

Property:

ControlToValidate-Validated controls
Onservervalidationfunction server-side validation function name
ClientValidationFunction Client Validation function name

Cases:

<script language= "C #" runat= "Server" >
BOOL ServerValidate (Object source,string value) {
...
}
</script>
<asp:customvalidator id= "Customvalidate" runat= "Server"
Controltovalidate= "Text1"
onservervalidationfunction= "ServerValidate"
clientvalidationfunction= "Clientvalidate" >

Not an even number Oh!

</asp:CustomValidator>
<script language= "JavaScript" >
function Clientvalidate (source,value)
{
......
}
</Script>
(Connect to a complete validator page) for more information:
Email Address Verification Program
Asp. NET validation controls

Second, the DATAGRID

Here's the code to display a datasheet in a DataGrid

<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.ADO"%>
<script language= "VB" runat= "Server" >
Sub Page_Load (Sender as Object, E as EventArgs)
Dim Conn as ADOConnection
Dim Dtcmd as Adodatasetcommand
Dim DS as DataSet
Dim Str_sql as String
Dim str_conn As String
Str_sql = "SELECT * FROM Test"
Str_conn = "dbq=" &server.mappath ("Test.mdb") & ";D river={microsoft Access Driver (*.mdb)};"
Connobj = New adoconnection (str_conn)
Dtscmdobj = New Adodatasetcommand (str_sql, Connobj)
Dtsobj = New DataSet ()
Dtscmdobj.filldataset (dtsobj, "test")
Dtgrid. DataSource = Dtsobj. Tables ("Test"). DefaultView
Dtgrid. DataBind ()
End Sub
</script>

<body>
<asp:datagrid id= "Dtgrid" headerstyle-font-bold= "True" tooltip= "data Grid provided with asp+" runat= "Server" Mainta Inviewstate= "false"/>
</body>

The DataGrid object binds the data source with the DataBind () method.

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.