[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

setting up multi-field ID verification

Posted on 2007-10-03
8
Medium Priority
?
335 Views
Last Modified: 2013-12-17
I am trying to set up a duplicate set of text fields that concatenate their values with hyphens as a string variable (id and id2). The second field set is for the user to re-enter the same ID to verify against the first. I need to know how to set this up. Here is the .cs and .aspx code:

protected void startBtn_Click(object sender, EventArgs e)

    {

        //Participant ID, concatenate three text boxes with "-"

        string id = ((TextBox)LoginView1.FindControl("TBid")).Text + "-"

                    + ((TextBox)LoginView1.FindControl("TBid1")).Text + "-"

                    + ((TextBox)LoginView1.FindControl("TBid2")).Text;

 

        //validate ID

        if (id == "--")//no ID entered

        {

            ((Label)LoginView1.FindControl("ErrorLabel1")).Text = "ID required!";

            return;

        }

        else

        {

            //regular expression to format ID

            Regex pattern = new Regex("[0-9]-[0-9][0-9]-[0-9][0-9][0-9]");

            if (!pattern.IsMatch(id)) //ID is not in the format

            {

                ((Label)LoginView1.FindControl("ErrorLabel1")).Text = "Invalid ID: format 9-99-999!";

                return;

            }

 

        //Re-entered participant ID, concatenate three text boxes with "-"

        string id2 = ((TextBox)LoginView1.FindControl("TextBox1")).Text + "-"

                    + ((TextBox)LoginView1.FindControl("TextBox2")).Text + "-"

                    + ((TextBox)LoginView1.FindControl("Textbox3")).Text;

 

 

 

      <tr>

                         <td align="left" class="generaltext" style="width: 479px; height: 58px" bgcolor="#ffefd5">

                             &nbsp;Study ID:<asp:TextBox ID="TBid" runat="server" onkeyup="return autoTab(this, 1, event);"   Style="left: 10px;

                                 position: relative; top: 0px" Width="18px" Height="14px" MaxLength="1" CssClass="watermark"></asp:TextBox>

                             &nbsp; <span style="font-size: 16pt">- &nbsp;</span><asp:TextBox ID="TBID1" runat="server" onkeyup="return autoTab(this, 2, event);" Height="14px" MaxLength="2" Width="24px" CssClass="watermark"></asp:TextBox>

                             <span

                                     style="font-size: 16pt">-&nbsp; </span><asp:TextBox

                                 ID="TBid2" runat="server" onkeyup="return autoTab(this, 3, event);" Height="14px" MaxLength="3" Width="36px" CssClass="watermark"></asp:TextBox>&nbsp;

                             <asp:Label ID="errorLabel1" runat="server" ForeColor="Red" Width="253px"></asp:Label></td>

                     </tr>

                     

                     <tr>

                         <td align="left" class="generaltext" style="width: 479px; height: 58px" bgcolor="#ffefd5">

                             &nbsp;Re-enter Study ID:<asp:TextBox ID="TextBox1" runat="server" onkeyup="return autoTab(this, 1, event);"   Style="left: 10px;

                                 position: relative; top: 0px" Width="18px" Height="14px" MaxLength="1" CssClass="watermark"></asp:TextBox>

                             &nbsp; <span style="font-size: 16pt">- &nbsp;</span><asp:TextBox ID="TextBox2" runat="server" onkeyup="return autoTab(this, 2, event);" Height="14px" MaxLength="2" Width="24px" CssClass="watermark"></asp:TextBox>

                             <span

                                     style="font-size: 16pt">-&nbsp; </span><asp:TextBox

                                 ID="TextBox3" runat="server" onkeyup="return autoTab(this, 3, event);" Height="14px" MaxLength="3" Width="36px" CssClass="watermark"></asp:TextBox>&nbsp;

                             <asp:Label ID="Label4" runat="server" ForeColor="Red" Width="253px"></asp:Label></td>

                     </tr>
0
Comment
Question by:devabarry
  • 5
  • 3
8 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20012087
You can try out required field validator for first one

and compare filed validator cobtrol for comparing first & second
0
 

Author Comment

by:devabarry
ID: 20019479
OK, is this what you mean? I'm especially not sure if my CompareValidators are set up correctly. Does anything need to be done to the C# code, or just the ASP?

<tr>
                         <td align="left" class="generaltext" style="width: 479px; height: 58px" bgcolor="#ffefd5">
                             &nbsp;Study ID:<asp:TextBox ID="TBid" runat="server" onkeyup="return autoTab(this, 1, event);"   Style="left: 10px;
                                 position: relative; top: 0px" Width="18px" Height="14px" MaxLength="1" CssClass="watermark"></asp:TextBox>
                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="TBid"> </asp:RequiredFieldValidator>
                             &nbsp; <span style="font-size: 16pt">- &nbsp;</span><asp:TextBox ID="TBID1" runat="server" onkeyup="return autoTab(this, 2, event);" Height="14px" MaxLength="2" Width="24px" CssClass="watermark"></asp:TextBox>
                             <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TBid1"> </asp:RequiredFieldValidator>
                             <span
                                     style="font-size: 16pt">-&nbsp; </span><asp:TextBox
                                 ID="TBid2" runat="server" onkeyup="return autoTab(this, 3, event);" Height="14px" MaxLength="3" Width="36px" CssClass="watermark"></asp:TextBox>
                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TBid2"> </asp:RequiredFieldValidator>&nbsp;
                             <asp:Label ID="errorLabel1" runat="server" ForeColor="Red" Width="253px"></asp:Label></td>                                                      
                     </tr>
                     
                     <tr>
                         <td align="left" class="generaltext" style="width: 479px; height: 58px" bgcolor="#ffefd5">
                             &nbsp;Re-enter Study ID:<asp:TextBox ID="TextBox1" runat="server" onkeyup="return autoTab(this, 1, event);"   Style="left: 10px;
                                 position: relative; top: 0px" Width="18px" Height="14px" MaxLength="1" CssClass="watermark"></asp:TextBox>
                                  <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="Tbid" ErrorMessage="Value does not match above entry."> </asp:CompareValidator>
                             &nbsp; <span style="font-size: 16pt">- &nbsp;</span><asp:TextBox ID="TextBox2" runat="server" onkeyup="return autoTab(this, 2, event);" Height="14px" MaxLength="2" Width="24px" CssClass="watermark"></asp:TextBox>
                              <asp:CompareValidator ID="CompareValidator2" runat="server" ControlToCompare="Tbid1" ErrorMessage="Value does not match above entry."> </asp:CompareValidator>
                             <span
                                     style="font-size: 16pt">-&nbsp; </span><asp:TextBox
                                 ID="TextBox3" runat="server" onkeyup="return autoTab(this, 3, event);" Height="14px" MaxLength="3" Width="36px" CssClass="watermark"></asp:TextBox>&nbsp;
                                  <asp:CompareValidator ID="CompareValidator3" runat="server" ControlToCompare="Tbid2" ErrorMessage="Value does not match above entry."> </asp:CompareValidator>
                             <asp:Label ID="Label4" runat="server" ForeColor="Red" Width="253px"></asp:Label></td>
                           
                     </tr>
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20019620
only aspx page coe required.

the structure is like

<asp:CompareValidator
id="compval"
Display="dynamic"
ControlToValidate="txt1"
ControlToCompare="txt2"
ForeColor="red"
BackColor="yellow"
Type="String"
EnableClientScript="false"
Text="Validation Failed!"
runat="server" />

You have missed ControlToValidate property..........

and only one control is required

refer this link for example
http://www.w3schools.com/aspnet/showasp.asp?filename=demo_comparevalidator
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:devabarry
ID: 20019978
Thanks, that was very helpful. Here is what I think it should then look like; please verify. You mention only one control is required, I assume you mean for each textbox. Since I am validating 3 separate textboxes, 3 controls are included, correct? FYI the textboxes are concatenated with hyphens into a string variable that is sent to the database.

<tr>
                         <td align="left" class="generaltext" style="width: 479px; height: 58px" bgcolor="#ffefd5">
                             &nbsp;Study ID:<asp:TextBox ID="TBid" runat="server" onkeyup="return autoTab(this, 1, event);"   Style="left: 10px;
                                 position: relative; top: 0px" Width="18px" Height="14px" MaxLength="1" CssClass="watermark"></asp:TextBox>
                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="TBid"> </asp:RequiredFieldValidator>
                             &nbsp; <span style="font-size: 16pt">- &nbsp;</span><asp:TextBox ID="TBID1" runat="server" onkeyup="return autoTab(this, 2, event);" Height="14px" MaxLength="2" Width="24px" CssClass="watermark"></asp:TextBox>
                             <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TBid1"> </asp:RequiredFieldValidator>
                             <span
                                     style="font-size: 16pt">-&nbsp; </span><asp:TextBox
                                 ID="TBid2" runat="server" onkeyup="return autoTab(this, 3, event);" Height="14px" MaxLength="3" Width="36px" CssClass="watermark"></asp:TextBox>
                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TBid2"> </asp:RequiredFieldValidator>&nbsp;
                             <asp:Label ID="errorLabel1" runat="server" ForeColor="Red" Width="253px"></asp:Label></td>                                                      
                     </tr>
                     
                     <tr>
                         <td align="left" class="generaltext" style="width: 479px; height: 58px" bgcolor="#ffefd5">
                             &nbsp;Re-enter Study ID:<asp:TextBox ID="TextBox1" runat="server" onkeyup="return autoTab(this, 1, event);"   Style="left: 10px;
                                 position: relative; top: 0px" Width="18px" Height="14px" MaxLength="1" CssClass="watermark"></asp:TextBox>
                                  <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox1" ControlToCompare="Tbid" ErrorMessage="Value does not match above entry."> </asp:CompareValidator>
                             &nbsp; <span style="font-size: 16pt">- &nbsp;</span><asp:TextBox ID="TextBox2" runat="server" onkeyup="return autoTab(this, 2, event);" Height="14px" MaxLength="2" Width="24px" CssClass="watermark"></asp:TextBox>
                               <asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="TextBox2" ControlToCompare="Tbid1" ErrorMessage="Value does not match above entry."> </asp:CompareValidator>
                             <span
                                     style="font-size: 16pt">-&nbsp; </span><asp:TextBox
                                 ID="TextBox3" runat="server" onkeyup="return autoTab(this, 3, event);" Height="14px" MaxLength="3" Width="36px" CssClass="watermark"></asp:TextBox>&nbsp;
                                   <asp:CompareValidator ID="CompareValidator3" runat="server" ControlToValidate="TextBox3" ControlToCompare="Tbid2" ErrorMessage="Value does not match above entry."> </asp:CompareValidator>
                             <asp:Label ID="Label4" runat="server" ForeColor="Red" Width="253px"></asp:Label></td>
                           
                     </tr>
                     
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20020038
You have 3 text boxes ang you want to compare the 2nd and 3rd with the 1st one right ??

then you need Required fild validator with ech text box and Compare fild validator with 2nd & 3rd only.

and for 2nd text box  compare validator
ControlToValidate="txt2"
ControlToCompare="txt1"

and for 3rd text box  compare validator
ControlToValidate="txt3"
ControlToCompare="txt1"

0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20020056
<tr>
                         <td align="left" class="generaltext" style="width: 479px; height: 58px" bgcolor="#ffefd5">
                             &nbsp;Study ID:<asp:TextBox ID="TBid" runat="server" onkeyup="return autoTab(this, 1, event);"   Style="left: 10px;
                                 position: relative; top: 0px" Width="18px" Height="14px" MaxLength="1" CssClass="watermark"></asp:TextBox>
                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="TBid"> </asp:RequiredFieldValidator>
                             &nbsp; <span style="font-size: 16pt">- &nbsp;</span><asp:TextBox ID="TBID1" runat="server" onkeyup="return autoTab(this, 2, event);" Height="14px" MaxLength="2" Width="24px" CssClass="watermark"></asp:TextBox>
                             <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TBid1"> </asp:RequiredFieldValidator>
 <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TBID1" ControlToCompare="TBid" ErrorMessage="Value does not match above entry."> </asp:CompareValidator>
                         


   <span
                                     style="font-size: 16pt">-&nbsp; </span><asp:TextBox
                                 ID="TBid2" runat="server" onkeyup="return autoTab(this, 3, event);" Height="14px" MaxLength="3" Width="36px" CssClass="watermark"></asp:TextBox>
                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TBid2"> </asp:RequiredFieldValidator>&nbsp;
                             
 <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TBid2" ControlToCompare="TBid" ErrorMessage="Value does not match above entry."> </asp:CompareValidator>



<asp:Label ID="errorLabel1" runat="server" ForeColor="Red" Width="253px"></asp:Label></td>                                                      
                     </tr>
                     
0
 

Author Comment

by:devabarry
ID: 20020086
I have 3 textboxes in the first ID entry section: Tbid, Tbid1 and Tbid2. Then I have 3 textboxes in a 'repeat' ID entry section  to re-enter the ID: TextBox1, TextBox2 and TextBox3. What should happen is Tbid = TextBox1, Tbid2 = TextBox2, and Tbid2 = TextBox3. Then I know the user has entered an exact match and the initial ID can go to the database.
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 2000 total points
ID: 20020105
ok,

Your code is correct
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question