Relevant introducing:
Data validity is website place is indispensible. For easier examine the data that the person that use inputs is accurate, ASP.NET offerred data test and verify to accuse for process designing personnel. The data test and verify that ASP.NET offers accuses include. (Attention: To can display code, all code are in under " < " later and " > " before added blank space, discomfort is excused more please! ) :
| Accuse | Function |
| RequiredFieldValidator | Examine whether does some input field have data to input |
| RangeValidator | Examine whether is the data that some input field inputs inside specific limits |
| CompareValidator | Examine whether some input field is equal to, do not be equal to, be more than, do not be less than, be less than |
| ValidationSummary | Listed and all did not accuse through what examine |
| RegularExpressionValidator | Examine whether is some column accorded with criterion expression is regular |
| CustomValidator | Decide regulation of test and verify oneself |
STEP 1 designs a page
We go out with form design first probably frame. Because the COMMENTS in the database has in the watch
[Frame of graph 5-1 database]
) of COMMENT_ID(automatic number, FIRST_NAME(text) , LAST_NAME(text) , TELEPHONE(text) , EMAIL(text) , SUBMIT_DATE(date / time) , COMMENTS(remarks) , ANSWERED(Boer value) wait for a field. The page that pursues as follows was designed in the site according to needing us, name for Reg.aspx.
[Graph 5-2 first page]
Among them COMMENT_ID, can add automatically by ACCESS, ANSWERED does not need him user to add. In the acquiescent value of SUBMIT_DATE the setting is Now() , can keep the date that adds a record automatically by ACCESS.
In the ASP page previously, we can be passed
<Asp:tExtbox Id= &q uot; ... " Runat= " Server " other property / >
Can add Textbox to accuse in DreamweaverMX through clicking quick pushbutton. Setting ID is passed in shooting the dialog box that give, ) of type of Text Mode(dialog box, tool Tip(namely the mouse is hanged at accusing a clew) that go up, and Layout(style designs) , style Information(is used at installing) of input character format and Textbox frame format, will install accuse. Next graphs are the setting dialog box of Textbox.
[Graph 5-3 Textbox installs a dialog box 1]
[Graph 5-4 Textbox installs a dialog box 2]
[Graph 5-5 Textbox installs a dialog box 3]
As a result of data the character with COMMENT need much input, so need uses the Textbox that much input goes. The linage that needs a setting to Text Mode is MultiLine and input place to need only (Rows) can.
To produce additive event, still need a pushbutton. Click Forms label, click " Button " pushbutton is added.
The use of STEP2 data test and verify
As a result of First_name, last_name, telephone, email must be inputted, forget an input to prevent an user so, can add RequiredFieldValidator to accuse come test and verify accuses. Because accuse a meeting to have in occurrence test and verify by accident the content that the position that is in in its below the circumstance shows to test and verify has been illogical, reason should put data test and verify to accuse in proper place.
Of RequiredFieldValidator data tes t and verify accuse a grammar to be as follows:
<Asp:RRunat= of EquiredFieldValidato other property " Server " > make mistake information</ Asp:REquiredFieldValidator >
Or
<Asp:REquiredFieldValidator ErrorMessage=" makes mistake Runat= of information " other property " Server " / >
After clicking More Tags, the Validation Server that chooses ASP.NET Tags can see the data test and verify that has different kind control an option. We need to add test and verify to accuse an Asp:R at the back of the input casing of First_nameEquiredFieldValidator.
A setting accuses in RequiredfieldValidator in the window, control To Validate is to be the input that accuses a relevant couplet with this data test and verify to accuse ID, and the information that when data test and verify fails, Error Message shows namely. At the same time we can pass setting Layout, style Information wi ll choose wants form.
[Graph 5-6 test and verify controls an option]
[Graph 5-7 RequiredfieldValidator accuses a setting dialog box]
Use same method to add test and verify of another RequiredFieldValidato data to accuse at the back of Last_Name input casing at the same time. We can be saved now, preview a page. Should not input the data-in in casing in First_name and Last_name and when clicking Submit pushbutton, with respect to message of failure of meeting occurrence test and verify. If pursue,5-8 place is shown.
But we need a lot of time the data with valid test and verify, for instance zip code is 6 certainly, the Email address of the input needs to have specific form. Here uses RegularExpressionValidator to come with respect to need the effectiveness of data of test and verify. In registering a page originally, telephone and Email can be used come here accuse come test and verify.
[Dialog box of graph 5-8 RequiredfieldVa lidator]
[Graph 5-9 Email installs attribute]
Accuse an additive method with RequiredfieldValidator test and verify similar, click " More Tags. . " the choice adds data test and verify to accuse. Different place installs Validation Expression namely. Because Telephone needs to input 7-10 number, need to install as follows:
[0-9]{7, 10}
Its grammar is as follows:
[] : Use the character with acceptability definition, show small letter like A-z ' A ' - ' Z ' it is acceptability character, a-zA-Z shows acceptability all letter, and 0-9 expresses to be able to accept all figures.
{} : Use the character number that the definition must input, {7, 10} expresses to be able to input 7-10 character, {0, } expresses to be able to accept 0- many more infinite character.
' . ' : Express to input aleatoric character. . {0, } states acceptability 0- is many more infinite aleatoric character.
| : Express OR(or) , for example [A-Za-z] {3} | [0-9]{3} expresses to be able to accept 3 English letter or it is 3 numbers
() : Read to go to the lavatory, contain | Symbolic string is met normally by () in. For example ([A-Za-z]{3} | [0-9]{3}) .
\ : If contain [] , {} , () , | Wait for special symbol to must add \ before these string. .
Following it is a few more commonly used example:
Email: . {1, }@ . {1, }/ . . {1}
Phone (include area size) : \([0-9]{3, 4})\)[0-9]{7, 8}
Although cannot be its real data in order to make sure the user is inputted, but examine accuse can make sure the format is right.
[Graph 5-10 previews a page]
Accuse as to CompareValidator, its method of each attribute setting is as follows:
| Control To Compare | The setting is as relative as its accuse |
| Control To Validate | Setting and its photograph accuse associatedly |
| Value To Compare | Set relative value |
| Operator | Set relative concernSet relative concernBe equal to, do not be equal to, be more than, be more than be equal to, be less than, be less than be equal toBe less than be equal to |
| Type | Comparative data type |
| Error Message | Indication information |
[Graph 5-11 CompareValidator installs a dialog box]
CustomValitor setting method with its he accuses similar, but need handwritten function OnServerValidate(to be in Events) come data of test and verify.
[Graph 5-12CustomValitor installs a dialog box]
For example
<Asp:CUstomValidator Id= " CusValid " Runat= " Server " ControlToValidate= accuses an OnServerValidate= " TheFunction " > information signing up for a fault</ Asp:CUstomValidator >
<Script Language= " Vb " Runat= " Server " >
Function TheFunction(sender As Object, , value As String) As Boolean
... . .
Return...
End Function
</ Script >
This accuses a meeting to transfer TheFuncion function, if return,False can h ave news signing up for a fault.
RangeValidator accuses
[Graph 5-12 RangeValidatorr installs a dialog box]
Can pass Mininum Value() of the least value, maxinum Value(maximum) the limits that will set a value. Can set relative kind at the same time through Type, for example " String " , " Integer " wait. Other setting is similar to the setting of other component.
Still have a package: VAlidationSummary. Among them HeaderText setting looks up character, displayMode sets indication pattern, its are specific attribute is as follows:
| Property value | Meaning |
| List BulletList SingleParagraph | ErrorMessageBranch shows ErrorMessageCent show ErrorMessageShow same travel |
[Attribute of graph 5-13 ValidationSummary installs a dialog box]
Acting attach is main the source code of block:
<Table Width="75%" Height="594" Border="1" Cellpadding="1" Cellspacing="0" Bordercolor="#999999" >
<Tr>
<Td Width="22%" Height="22" >First Name</ Td >
<Td Width="38%" ><Asp:tExtbox BackColor="#CCCCCC" ForeColor="#0033FF" ID="first" Runat="server" TextMode="SingleLine" ToolTip="Please Input The First Name" MaxLength="40" BorderWidth="1" Width="200"/ ></ Td >
<Td Width="40%" ><Asp:rEquiredfieldvalidator BackCo lor="#CCCCCC" ControlToValidate="first" ErrorMessage="RequiredField" ForeColor="#FF0000" ID="validname" Runat="server" /></ Td >
</ Tr >
<Tr>
<Td Height="22" >Last Name</ Td >
<Td ><Asp:tExtbox BackColor="#CCCCCC" ForeColor="#0033FF" ID="Lastname" Runat="server" TextMode="SingleLine" Width="200" ToolTip="Please Input The Last Name" BorderWidth="1"/ ></ Td >
<Td ><Asp:rEquiredfieldvalidator BackColor="#CCCCCC" ControlToValidate="Lastname" ErrorMessage="RequiredField" ForeColor="#FF0000" ID="vailLast" Runat="server" /></ Td >
</ Tr >
<Tr>
<Td Height="22" >Telephone</ Td >
<Td ><Asp:tExtbox BackColor="#CCCCCC" BorderWidth="1" ForeColor="#0066FF" ID="telephone" Runat="server " TextMode="SingleLine" ToolTip="Please Input Your Telephone" Width="200" / ></ 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="22" >Email</ Td >
<Td ><Asp:tExtbox BackColor="#CCCCCC" BorderWidth="1" ForeColor="#0033FF" ID="email" Runat="server" TextMode="SingleLine" ToolTip="Please Input Your E-mail" Width="200"/ ></ 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="22" 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="16" Runat="server" TextMode="MultiLine" ToolTip="Please Input The Comments" Width="400"/ >
</ Div >
<Div Align="center "><Br >
</ Div ></ Td >
</ Tr >
<Tr >
<Td Height="71" Colspan="3" ><Div Align="center" >
<Asp:vAlidationsummary BackColor="#CCCCCC" DisplayMode="BulletList" ForeColor="#FF0000" HeaderText=" has by accident content includes:" ID="valSum" Runat="server" ToolTip="Error" / >
</ Div ></ Td >
</ Tr >
<Tr>
<Td Height="22" Colspan="3" ><Input Type="submit" Name="Submit" Value="Submit ">
</ Td >
</ Tr >
</ Table >
The form is as follows:
[Graph 5-14 is previewed]
STEP 3 data is added
The function that adds data as to implementation is simpler, we can install the function that adds data through guide, make DreamweaverMX automatic add code. Click the Server Behaviors label in Application, click after that + pushbutton chooses Insert Record(to be like graph 5-15) from which.
Want to determine the data cause that be linked together above all in shooting the dialog box that give. If was not found in list, can click Define pushbutton to set data source (the 5-16) that be like a graph. Insert Into Table is used at installing need to add the table of data, can mix text casing in Columns corresponding data source is opposite should, set data kind. On Success, the page that if add number to turn according to jumping successfully,the setting is in Go To. On Failure, can install in Go To add data failure to jump the page that turns, at the same time we also can choose Display Debugging Information On Failure the setting is adding addend to show information signing up for a fault according to failing.
[Graph 5-15 chooses Insert Record]
[Graph 5-16 data adds set]
Le t us read additive code:
<MM:INsert
Runat="server "
CommandText='<%# "INSERT INTO COMMENTS (COMMENTS, EMAIL, FIRST_NAME, LAST_NAME, TELEPHONE) VALUES (? , ? , ? , ? , ? ) " % >'
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" />
<P arameter Name="@EMAIL" Value='<%# IIf((Request.Form("email" )<>Nothing) , request.Form("email") , "") % >' Type="WChar" />
<Parameter Name="@FIRST_NAME" Value='<%# IIf((Request.Form("first" )<>Nothing) , request.Form("first") , "") % >' 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 adds a database with Yu Tian, parameter is used at assigning the numerical value of parameter namely.
The code in front is used at appointing a database namely link and the pa ge that turns jumps after adding a success, add failure to display wrong message, still have associated form.
Him MacroMedia develops these, need the support of a few component of Macromedia, with the standard code pattern of on the net a lot of ASP.net is different now. Ask everybody to consult code when the standard code form that does not want according to this code wrong understanding ASP.net. Standard code format everybody can consult Www.gotdotnet.com. If everybody wants to write standard code, can use WebMatrix, download address: Http://www.asp.net/webmatrix/download.aspx? Tabindex=4

No comments:
Post a Comment