Requirement: if there are four columns in sequence, when the second column is empty, the third column cannot have values, and so on.
Front-end:
- <% @ Page Language = "C #" autoeventwireup = "true" codefile = "checknull. aspx. cs" inherits = "test_checknull" %>
- <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <HTML xmlns = "http://www.w3.org/1999/xhtml">
- <Head runat = "server">
- <Title> not added before, not later. </Title>
- <SCRIPT type = "text/JavaScript">
- // Function. It is not written before and cannot be added later.
- // The expected improvement is that an array can be input and determined based on the array length.
- Function fnotnull (){
- // Boolean B = true; // The boolean type fails.
- VaR B = 0; // 0 indicates that verification is passed, and 1 indicates that verification is not passed.
- If (document. getelementbyid ('tb1 '). value = "")
- B = 1;
- For (I = 1; I <5; I ++) {// set the ID range.
- VaR T = 'tb' + I;
- VaR TXT = Document. getelementbyid (t );
- If (txt. value = "") // if it is null, the system checks whether there is a value next to it.
- For (j = I + 1; j <5; j ++) {// you can specify the ID range. This should start with I + 1.
- VaR x = 'tb' + J;
- VaR TT = Document. getelementbyid (X );
- If (TT. value! = "")
- B = 1;
- }
- }
- Return B;
- }
- Function fcheck (){
- If (fnotnull () = "0 ")
- Alert ('verified ');
- Else
- Alert ('the first column cannot be blank and cannot be added across rows! ');
- }
- </SCRIPT>
- </Head>
- <Body>
- <Form ID = "form1" runat = "server">
- <Div>
- <Asp: textbox id = "tb1" runat = "server"> </ASP: textbox>
- <Asp: textbox id = "tb2" runat = "server"> </ASP: textbox>
- <Asp: textbox id = "int32" runat = "server"> </ASP: textbox>
- <Asp: textbox id = "tb4" runat = "server"> </ASP: textbox>
- <Input type = "button" value = "JS Verification" onclick = "fcheck ();"/>
- <Asp: button id = "btncheck" runat = "server" text = "C # verify" onclick = "btncheck_click"/>
- </Div>
- </Form>
- </Body>
- </Html>
Background:
- Using system;
- Using system. Data;
- Using system. configuration;
- Using system. collections;
- Using system. Web;
- Using system. Web. Security;
- Using system. Web. UI;
- Using system. Web. UI. webcontrols;
- Using system. Web. UI. webcontrols. webparts;
- Using system. Web. UI. htmlcontrols;
- Public partial class test_checknull: system. Web. UI. Page
- {
- Protected void page_load (Object sender, eventargs E)
- {
- }
- Protected void btncheck_click (Object sender, eventargs E)
- {
- If (checknull ())
- Response. Write ("verified! ");
- Else
- Response. Write ("the first column cannot be blank and cannot be added to the second row! ");
- }
- /// <Summary>
- /// Determine whether data is written in the same row.
- /// </Summary>
- /// <Returns> </returns>
- Private bool checknull ()
- {
- Bool B = true;
- Arraylist arr = new arraylist ();
- Arr. Add (this. tb1.text. Trim ());
- Arr. Add (this. tb2.text. Trim ());
- Arr. Add (this. tb3.text. Trim ());
- Arr. Add (this. tb4.text. Trim ());
- For (INT I = 0; I <arr. Count; I ++)
- {
- If (ARR [I]. tostring () = "") // If the column is empty, check whether the column is followed by a value.
- For (Int J = I + 1; j <arr. Count; j ++)
- {
- If (ARR [J]. tostring ()! = "")
- B = false;
- }
- }
- Return B;
- }
- }
End