Dreamwavermx and asp.net (v)

Source: Internet
Author: User
Tags add date format define expression net numeric value string
asp.net . Create a Message page----data validation control and add data

Related introduction:

The correctness of the data is necessary for the website. To make it easier to verify that the data entered by the user is correct, the ASP. NET provides a data validation control for programmers. Asp. NET provides data validation controls that include. (Note: In order to be able to display the code, all of the following code in the "<" and ">" before adding a space, inconvenience please forgive! ):

Control

Function

RequiredFieldValidator

Verify that the input column has data entry

RangeValidator

Verify that the data entered in an input field is within a specific range

CompareValidator

Verify that an input column is equal to, not equal to, greater than, not less than, less than

ValidationSummary

List all controls that have not been validated

RegularExpressionValidator

Verify that a column conforms to a regular expression rule

CustomValidator

Custom validation Rules



Step 1 Design Page
Let's use a table to design the approximate framework. Because the comments table in the database has


[Figure 5-1 Database Framework]

COMMENT_ID (AutoNumber), first_name (text), last_name (text), telephone (text), EMAIL (text), submit_date (date/time), COMMENTS (remark), answered Fields such as Boolean values. According to the need we design the following page in the site, named Reg.aspx.


[Figure 5-2 Original page]

Where comment_id, which can be automatically added by access, answered do not need to be added by the user. When the default value for Submit_date is set to now (), access is automatically written to the date on which the record was added.

In previous ASP pages, we can enter data by setting the input box. Asp. NET with a TextBox control to accept the data, the syntax is as follows:

< Asp:textbox id= "..." runat= "Server" other properties/>

You can add a TextBox control in DREAMWEAVERMX by clicking the shortcut button. In the pop-up dialog box, set Id,text mode (dialog type), tool tip (that is, the mouse hovers over the control), and layout (style design), style information (for formatting input text and textbox border format), To set the control. The following figure is the Setup dialog box for the textbox.


[Figure 5-3 TextBox Setup dialog box 1]




[Figure 5-4 TextBox Setup dialog box 2]


[Figure 5-5 TextBox Setup dialog box 3]

Because the data item comment needs to enter a lot of text, you need to use a textbox with multiple input lines. Simply set text mode to multiline and enter the desired number of rows (rows).

A button is also required in order to produce an added event. Click the Forms tab and click the Button button to add.

use of STEP2 data validation

Because First_name,last_name,telephone,email must be entered, to prevent users from forgetting to enter, you can add RequiredFieldValidator controls to validate the control. Because the control displays the validation failure in its place where validation is incorrect, the data validation control should be placed in the appropriate place.

The control syntax for RequiredFieldValidator data validation is as follows:

< Asp:requiredfieldvalidato other properties runat= "Server" > Error message </asp:requiredfieldvalidator >

Or

< Asp:requiredfieldvalidator errormessage= "error message" Other properties runat= "Server"/>

After clicking more tags, select asp.net tags validation server can see different types of data validation control options. We need to add the validation control Asp:requiredfieldvalidator after the first_name input box.

In the RequiredFieldValidator Control Settings window, the control to validate is the ID of the input controls associated with this data validation control, and the error message is the information that is displayed when data validation fails. At the same time we can select the desired style by setting layout,style information.


[Figure 5-6 Validation control selection]


[Figure 5-7 RequiredFieldValidator Control Settings dialog box]

Add another Requiredfieldvalidato data validation control in the same way after the last_name input box. Now we can save and preview the page. Validation failure messages occur when you do not enter data in the first_name and last_name input boxes and click the Submit button. As shown in Figure 5-8.

But many times we need to validate valid data, such as a postal code must be 6 digits, the input email address needs to have a specific form. Here you need to use RegularExpressionValidator to verify the validity of the data. In this registration page, telephone and email can be used to verify this control.


[Figure 5-8 RequiredFieldValidator dialog box]




[Figure 5-9 Email Settings Properties]

Similar to the method added with the RequiredFieldValidator validation control, click "More Tags ..." Select Add data validation control. The different place is to set up validation Expression. Because telephone needs to enter 7-10 digits, you need to set the following:

[0-9] {7,10}

The syntax is as follows:

[]: Used to define acceptable characters, such as a-Z indicating that lowercase ' a '-' Z ' is an acceptable character, a-za-z that all letters can be accepted, and 0-9 means that all numbers are acceptable.

{}: Used to define the number of characters that must be entered, {7,10} indicates that 7-10 characters can be entered, {0}, which indicates that 0-infinitely many characters can be accepted.

‘.’ : Indicates that any character is entered ... {0,} represents an acceptable 0-infinite number of arbitrary characters.

| : Represents or (or), for example, [a-za-z]{3}| [0-9] {3} can accept 3 English letters or 3 digits

(): In order to facilitate reading, the string containing the | symbol is usually (). For example ([a-za-z]{3}|[ 0-9]{3}).

\: If there are [],{}, (), | Special symbols must precede these strings plus \ ...

The following are some of the more common examples:

Email:. {1,}@. {1,}/.. {1}

Telephone (including area code): \ ([0-9]{3,4}) \) [0-9]{7,8}

Although the user input is not guaranteed to be its true data, the validation control ensures that the format is right.


[Figure 5-10 Preview page]

As for the CompareValidator control, its properties are set as follows:

Control to Compare

Set the control to compare with

Control to Validate

Set the controls associated with them

Value to Compare

Set the value of a comparison

Operator

Set the relationship of the comparison (equal to, not equal to, greater than, greater than or equal to, less than, less than or equal to)

Type

Data type of comparison

Error message

Display information



[Figure 5-11 CompareValidator Settings dialog box]

The Customvalitor setting method is similar to other controls, but requires the handwriting function onservervalidate (in events) to validate the data.


[Figure 5-12customvalitor Settings dialog box]

For example

< Asp:customvalidator id= "Cusvalid" runat= "Server" controltovalidate= control name onservervalidate= "Thefunction" > Error information </asp:customvalidator >

< script language= "VB" runat= "Server" >

Function thefunction (sender as object,,value as String) as Boolean

........

Return ...

End Function

</script >

This control invokes the Thefuncion function, and if False returns an error message.
RangeValidator control


[Figure 5-12 Rangevalidatorr Settings dialog box]

You can set the range of values by Mininum value (minimum), Maxinum value (maximum). You can also set the type of comparison by type, such as "string", "Integer", and so on. Other settings are similar to those of other components.

There is also a component: ValidationSummary. Where HeaderText sets the header text, DisplayMode sets the display mode with the following properties:

Property value

Significance

List

BulletList

Singleparagraph

ErrorMessage Branch Display

ErrorMessage Item Display

ErrorMessage Display Chengtong row



[Figure 5-13 ValidationSummary Property Settings dialog box]

The source code for the main program section is attached:

< table width= "75%" height= "594" border= "1" cellpadding= "1" cellspacing= "0" bordercolor= "#999999" >

< tr >

< TD width= "22%" height= ">first name</td >

< TD width= "38%" >< asp:textbox backcolor= "#CCCCCC" forecolor= "#0033FF" id= "" "," runat= "," Server "Textmode=" Singleline "tooltip=" Please input the "maxlength=" borderwidth= "1" width= "/></td >

< TD width= "40%" >< asp:requiredfieldvalidator backcolor= "#CCCCCC" controltovalidate= "" "Errormessage=" Requiredfield "forecolor=" #FF0000 "id=" Validname "runat=" Server "/> </td >

</tr >

< tr >

< TD height= ">last" name</td >

< TD >< Asp:textbox backcolor= "#CCCCCC" forecolor= "#0033FF" id= "Lastname" runat= "Server" textmode= "Singleline "Width=" tooltip= "Please input the" "borderwidth=" 1 "/></td >

< TD >< Asp:requiredfieldvalidator backcolor= "#CCCCCC" controltovalidate= "Lastname" errormessage= " Requiredfield "forecolor=" #FF0000 "id=" Vaillast "runat=" Server "/> </td >

</tr >

< tr >

< TD height= >Telephone</td >

< TD >< Asp:textbox backcolor= "#CCCCCC" borderwidth= "1" forecolor= "#0066FF" id= "Telephone" runat= "server" Textmode= "Singleline" tooltip= "Please input your telephone" width= ""/></td >

< td > < Asp:regularexpressionvalidator backcolor= "#CCCCCC" controltovalidate= "Telephone" errormessage= "7-10 Numbers required "forecolor=" #FF0000 "id= Vailtel" runat= "Server" validationexpression= "[0-9]{7,10}"/> < asp: RequiredFieldValidator backcolor= "#CCCCCC" controltovalidate= "Telephone" errormessage= "Requiredfield" ForeColor= "# FF0000 "id=" Vailtel2 "runat=" Server "/></td >

</tr >

< tr >

< TD height= >Email</td >

< TD >< Asp:textbox backcolor= "#CCCCCC" borderwidth= "1" forecolor= "#0033FF" id= "email" runat= "Server" TextMode = "Singleline" tooltip= "Please input your e-mail" width= "/></td >

< TD >< Asp:regularexpressionvalidator backcolor= "#CCCCCC" controltovalidate= "email" errormessage= " Invaliate Email Address "forecolor=" #FF0000 "id=" Valiemail "runat=" Server "validationexpression=". {1,}@. {3,} "/> < Asp:requiredfieldvalidator backcolor=" #CCCCCC "controltovalidate=" email "errormessage=" Required Field "forecolor=" #FF0000 "id=" VALIEMAIL2 "runat=" Server "/> </td >

</tr >

< tr >

< TD height= "Colspan=" "3" >< div align= "center" >Comments</div ></td >

</tr >

< tr >

< TD height= "188" colspan= "3" >< div align= "center" >

< Asp:textbox backcolor= "#CCCCCC" borderwidth= "1" forecolor= "#0033FF" id= "Comments" rows= "" runat= "Server" Textmode= "MultiLine" tooltip= "please input the Comments" width= "/>

</div >

< div align= "center" > < br >

</div ></td >

</tr >

< tr >

< TD height= "Colspan=" "3" >< div align= "center" >

< asp:validationsummary backcolor= "#CCCCCC" displaymode= "BulletList" forecolor= "#FF0000" headertext= "the wrong content includes:" ID = "Valsum" runat= "Server" tooltip= "Error"/>

</div ></td >

</tr >

< tr >

< TD height= "Colspan=" "3" >< input type= "submit" name= "submit" value= "Submit" >

</td >

</tr >

</table >

The style is as follows:


[Figure 5-14 Preview]
Step 3 Data add

As for the implementation of the function of adding data is simpler, we can set the function of adding data through the wizard, and let dreamweavermx add code automatically. Click the Server Behaviors tab in application, and then click the + button to select the Insert record from (Figure 5-15).

In the pop-up dialog box, first determine the connected data source. If not found in the list, you can click the Define button to set the data source (Figure 5-16). Insert into table is used to set up a table in which data needs to be added, and the columns can correspond to the text box and corresponding data source and set the data type. On Success,go to is the page that sets if the data you are adding succeeds to jumping to. In Failure,go to, you can set the page where the add data failed to jump to, and we can also select Display debugging information on failure setting to show an error message when adding data failure.


[Figure 5-15 Select Insert Record]


[Figure 5-16 Data add set]

Let's take a look at the added code:

< Mm:insert

runat= "Server"

Commandtext= ' <% # ' INSERT into COMMENTS (COMMENTS, EMAIL, first_name, last_name, telephone) VALUES (?,?,?,?,?) "% & gt; '

Connectionstring= ' <% # System.Configuration.ConfigurationSettings.AppSettings ("Mm_connection_string_location" )% > '

Databasetype= ' <% # System.Configuration.ConfigurationSettings.AppSettings ("Mm_connection_databasetype_ Location ")% > '

Expression= ' <% # Request.Form ("Mm_insert") = "Form1"% > '

Createdataset= "false"

Successurl= ' <% # "index.htm"% > '

Failureurl= ' <% # "reg.aspx"% > '

Debug= "true"

>

< Parameters >

< Parameter name= "@COMMENTS" value= ' <% # IIf (Request.Form ("COMMENTS") < > Nothing), Request.Form ("COMMENTS ")," ")% > ' type=" WChar "/>

< Parameter name= "@EMAIL" value= ' <% # IIf (request.form ("email" < > Nothing), Request.Form ("email"), "")% &G t; ' Type= "WChar"/>

< Parameter name= "@FIRST_NAME" value= ' <% # IIf (Request.Form ("a") < > Nothing), Request.Form ("a"), " ")% > ' type=" WChar "/>

< Parameter name= "@LAST_NAME" value= ' <% # IIf (Request.Form ("Lastname") < > Nothing), Request.Form (" Lastname ")," ")% > ' type=" WChar "/>

< Parameter name= "@TELEPHONE" value= ' <% # IIf (Request.Form ("Telephone") < > Nothing), Request.Form (" Telephone ")," ")% > ' type=" WChar "/>

</parameters >

</mm:insert >

Mm:insert is the label that Dreamweaver uses to add a database, parameter is the numeric value that specifies the parameter.

The preceding code is the page used to specify the database link and to jump to when the addition succeeds, add failure to display an error message, and the associated table.

These are Macromedia developed by themselves, need to Macromedia some component support, and now online many asp.net standard code format different. Please refer to the code when you do not according to this code and wrong understanding of ASP.net standard code format. Standard code format you can refer to www.gotdotnet.com. If you want to write standard code, you can use WebMatrix, download the address: http://www.asp.net/webmatrix/download.aspx?tabindex=4



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.