[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to change the appearance of a textbox when it is disabled

Posted on 2011-05-10
12
Medium Priority
?
354 Views
Last Modified: 2012-05-11
I have a code which disables certain textboxes when specific values are selected from a drop down list using a javascript code.  Is there any way to change the appearance of the textboxes to show that they are disabled?  Here is the javascript code used to disable/enable textboxes:

 
<script language="javascript">

                       function enableListItem() {
                           form1.DropDownList1.enabled = true;
                       }


                       function setEnabledTextBoxes(ddl) {
                           switch (ddl.value) {
                               case "A":
                               case "B":
                               case "C":
                               case "D":
                               case "E":
                              
                                                 
                                   document.getElementById("TB3").disabled = false;
                                   document.getElementById("TB4").disabled = true;
                                   break;
                               case "Mortgage":
                               
                                   document.getElementById("TB3").disabled = true;
                                   document.getElementById("TB4").disabled = false;
                                   break;
                               default:
                                   break;
                           }
                       }
</script>

Open in new window


thanks!
0
Comment
Question by:sarah_siu
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 8

Accepted Solution

by:
imantas earned 1336 total points
ID: 35732771
Instead of setting property "disabled" to true, you should try setting attribute "disabled" to "disabled":
<script language="javascript">

                       function enableListItem() {
                           form1.DropDownList1.enabled = true;
                       }


                       function setEnabledTextBoxes(ddl) {
                           switch (ddl.value) {
                               case "A":
                               case "B":
                               case "C":
                               case "D":
                               case "E":
                              
                                                 
                                   document.getElementById("TB3").disabled = false;
                                   document.getElementById("TB4").disabled = true;
                                   break;
                               case "Mortgage":
                               
                                   document.getElementById("TB3").setAttribute('disabled', 'disabled');
                                   document.getElementById("TB4").setAttribute('disabled', 'disabled');
                                   break;
                               default:
                                   break;
                           }
                       }
</script>

Open in new window


So then you can apply simple CSS code to change their appearance:
*[disabled="disabled"] {
  background-color: silver;
}

Open in new window


change * to the according tag if you don't want all disabled elements to have this style, for example if your text boxes are inputs:
input[disabled="disabled"] {
  background-color: silver;
}

Open in new window

0
 
LVL 7

Assisted Solution

by:m4trix
m4trix earned 664 total points
ID: 35732778
Absolutely! Is there a particular look you're going for?

One option is to hide it entirely (this will make the box disappear):
document.getElementById("TB4").style.display = "none";

you could make the background color change:
document.getElementById("TB4").style.background = "red"

Is that the kind of thing you're going for?
0
 
LVL 8

Assisted Solution

by:imantas
imantas earned 1336 total points
ID: 35732785
Sorry, the javascript code I've provided is a bit incorrect, here's the correct one:
<script language="javascript">

                       function enableListItem() {
                           form1.DropDownList1.enabled = true;
                       }


                       function setEnabledTextBoxes(ddl) {
                           switch (ddl.value) {
                               case "A":
                               case "B":
                               case "C":
                               case "D":
                               case "E":
                              
                                                 
                                   document.getElementById("TB3").setAttribute('disabled', '');
                                   document.getElementById("TB4").setAttribute('disabled', 'disabled');
                                   break;
                               case "Mortgage":
                               
                                   document.getElementById("TB3")..setAttribute('disabled', 'disabled');
                                   document.getElementById("TB4")..setAttribute('disabled', '');
                                   break;
                               default:
                                   break;
                           }
                       }
</script>

Open in new window

0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 9

Expert Comment

by:radcaesar
ID: 35732914
Use JQuery or some other JLibs
0
 

Author Comment

by:sarah_siu
ID: 35732924
Hi, Actually,  style.display = "none";  was what i was looking for.  i don't want the users to be able to input anything in those fields.  It worked when inserted that into my code.

But...I have validations for all the textboxes.  After I press submit, and if one of the textboxes fails the validation criteria, the disabled textboxes reappear...is there anyway to suppress the textboxes completely until the data has been submitted successfully?

0
 
LVL 8

Expert Comment

by:imantas
ID: 35733007
So you want them to be disabled even when page is reloaded after submit?
0
 

Author Comment

by:sarah_siu
ID: 35733039
If the data on the form has not been submitted successfully, I would like the textboxes to be disabled until the form IS submitted successfully.

Once the form is submitted successfully, i would like all the textboxes to reappear...
0
 
LVL 8

Expert Comment

by:imantas
ID: 35733080
I'm not sure what you mean by saying "successfully". Do you use AJAX to submit your form or just some error message that is added when page is reloaded after pressing "submit"?
0
 

Author Comment

by:sarah_siu
ID: 35733122
I'm actually doing the code on visual web developer - VB.NET.

When i press submit, the textboxes are validated before an action is executed (in this case, before the data is passed to an SQL server in the back end).

Currently, when i press submit, and lets say one of the textboxes do not meet the validation criteria, then an error message will pop up saying "require valid ID" and when that happens, all the disabled textboxes pop up again.  

I would like for these disabled textboxes to remain disabled until the user successfully submits the form.  Upon successful submission, then the blank form will display all the textboxes again...

hope i'm being clear...
0
 
LVL 7

Expert Comment

by:m4trix
ID: 35733127
sarah, would you be able to post more of your code? I'm sure it can be done, but without seeing what your validation code looks like (or for that matter the rest of your page) it's difficult to recommend a solution
0
 

Author Comment

by:sarah_siu
ID: 35733251
I actually have 2 parts to my code, on on the client side and server side.  

 
<%@ Page Language="VB" AutoEventWireup="false" 

CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
    
     <script language="Javascript">
      <!--
         function isNumberKey(evt) {
             var charCode = (evt.which) ? evt.which : event.keyCode
             if (charCode > 31 && (charCode < 48 || charCode > 57))
                 return false;

             return true;
         }
      //-->
    </script>

    <script language="JavaScript">
<!--
        window.history.forward(1); //-->
    </script>
    
</head>
<body>
    <form id="form1" runat="server" autocomplete="off">
    <div>
        <table style="width: 700px; height: 100px; text-align: left">
            <tr>
                <td colspan="5" style="width: 3992px; height: 61px">
                    <span style="font-size: 24pt"><span style="color: 

#660033"><strong>TESTING</strong></span> 
                        &nbsp;&nbsp;
                    </span></td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px; height: 17px">
                </td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px; height: 21px">
                    <span style="font-family: Arial">Date: &nbsp; &nbsp; 

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

&nbsp; &nbsp; &nbsp;
                        <asp:Label ID="lbldate" runat="server" 

Width="161px"></asp:Label></span></td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px">
                    <span style="font-family: Arial">Tb1: &nbsp; &nbsp; 

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

&nbsp;&nbsp; </span>&nbsp;<asp:TextBox ID="TB1" 

runat="server" BackColor="LightGray" ForeColor="Black" 

MaxLength="6" ToolTip="i.e. XX1234"></asp:TextBox>
                    <asp:Label ID="lblTb1" runat="server" 

Width="352px" BorderColor="Red" Font-Bold="True" 

Font-Names="Arial" Font-Size="Smaller" 

ForeColor="Red"></asp:Label></td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px; height: 6px">
                    <span style="font-family: Arial">Tb2: &nbsp; &nbsp; 

&nbsp; &nbsp; &nbsp; &nbsp;
                        &nbsp; &nbsp; &nbsp; 

</span>&nbsp;<asp:TextBox
                        ID="Tb2" runat="server" onkeypress="return 

isNumberKey(event)" BackColor="LightGray" 

ForeColor="Black" MaxLength="10" ToolTip="i.e. 

0001234567"></asp:TextBox>
                    <asp:Label ID="lblTb2" runat="server" 

Width="358px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label></td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px; height: 15px">
                    <br />
                </td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px; height: 27px">
                    <asp:RadioButtonList ID="RadioButtonList1" 

runat="server" Font-Names="Arial" 

RepeatDirection="Horizontal"
                        Width="335px">
                        <asp:ListItem Value="Option 1"></asp:ListItem>
                        <asp:ListItem Value="Option 2"></asp:ListItem>
                    </asp:RadioButtonList><asp:Label ID="lblrbl1" 

runat="server" Width="333px" Font-Bold="True" 

Font-Names="Arial" Font-Size="Smaller" 

ForeColor="Red"></asp:Label>&nbsp;
                   
</td>
            </tr>
            <tr style="font-family: Arial TUR; font-size: 12pt;">
                <td colspan="5" style="width: 3992px; height: 28px">
                </td>
            </tr>
            <tr style="font-family: Arial TUR; font-size: 12pt;">
                <td colspan="5" style="width: 3992px; height: 39px; 

border-top-style: solid; border-top-color: #660033;" 

bordercolor="#000000" bordercolorlight="#330033">
                    <span><span style="font-size: 16pt; font-family: 

Arial Baltic">PRODUCT INFORMATION:</span></span></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px" 

bordercolor="#000000" bordercolorlight="#330033">
                    <asp:RadioButtonList ID="RadioButtonList2" 

runat="server" Font-Names="Arial" 

RepeatDirection="Horizontal"
                        Width="600px">
                        <asp:ListItem Value="1">Option 3</asp:ListItem>
                        <asp:ListItem Value="2">Option 4</asp:ListItem>
                    </asp:RadioButtonList><asp:Label ID="lblrbl2" 

runat="server" Width="600px" Font-Bold="True" 

Font-Names="Arial" Font-Size="Smaller" 

ForeColor="Red"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 48px; 

border-bottom-color: #660033; border-bottom-style: solid;" 

bordercolor="#000000" bordercolorlight="#330033">

                    <asp:DropDownList ID="DropDownList1" 

runat="server" Width="165px" 

onchange="setEnabledTextBoxes(this);">
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem Text ="A" 

Value="A"></asp:ListItem>
                        <asp:ListItem Text = "B" 

Value="B"></asp:ListItem>
                        <asp:ListItem Text = "C" 

Value="C"></asp:ListItem>
                        <asp:ListItem Text = "D" 

Value="D"></asp:ListItem>
                  </asp:DropDownList>
                   <script language="javascript">

                       function enableListItem() {
                           form1.DropDownList1.enabled = true;
                       }


                       function setEnabledTextBoxes(ddl) {
                           switch (ddl.value) {
                               case "A":
                               case "B":
                               case "C":
                                   document.getElementById("TB3").disabled 

= false;
                                   document.getElementById("TB4").disabled 

= true;
                                   break;
                               case "D":
                               case "E":
                                   document.getElementById("TB3").disabled 

= true;
                                   document.getElementById("TB4").disabled 

= false;
                                   break;
                               default:
                                   break;
                           }
                       }
</script>

                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    &nbsp;<asp:DropDownList ID="DropDownList2" 

runat="server" Width="165px" AutoPostBack="true" 

onselectedindexchanged="DropDownList1_SelectedIndexChang

ed">
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem Text = "1" 

Value="1"></asp:ListItem>
                        <asp:ListItem Text = "2" 

Value="2"></asp:ListItem>
                        <asp:ListItem Text = "3" 

Value="3"></asp:ListItem>
                        <asp:ListItem Text = "4" 

Value="4"></asp:ListItem>
                        
                    </asp:DropDownList>&nbsp;<br />
                    <asp:Label ID="lblproduct" runat="server" 

Width="247px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label>
                    &nbsp;&nbsp; &nbsp;<asp:Label ID="lblproduct2" 

runat="server" Width="261px" Font-Bold="True" 

Font-Names="Arial" Font-Size="Smaller" 

ForeColor="Red"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px">
                </td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px">
                    <span style="font-family: Arial TUR">Tb3:</span>
                    <asp:TextBox ID="TB3" runat="server" 

onkeypress="return isNumberKey(event)" 

BackColor="LightGray" ForeColor="Black "
                        Width="180px" MaxLength="10" 

Enabled="False"></asp:TextBox>
                    <asp:Label ID="lblTB3" runat="server" 

Width="352px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px">
                    <span style="font-family: Arial">TB4: &nbsp;<span 

style="font-family: Times New Roman">
                        &nbsp; &nbsp;&nbsp; </span></span> 

<asp:TextBox ID="TB4" runat="server" onkeypress="return 

isNumberKey(event)" BackColor="LightGray"
                        ForeColor="Black" Width="182px" 

MaxLength="10" Enabled="False"></asp:TextBox>
                    <asp:Label ID="lblTB4" runat="server" 

Width="352px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label></td>
            </tr>
            <tr style="font-family: Times New Roman">
                <td colspan="5" style="width: 3992px; height: 28px">
                    <span style="font-family: Arial">TB5: 

</span>&nbsp; &nbsp;&nbsp;
                    <asp:TextBox ID="TB5" runat="server" 

onkeypress="return isNumberKey(event)" 

BackColor="LightGray" ForeColor="Black"
                        Width="183px" MaxLength="10" 

Enabled="False"></asp:TextBox>
                    <asp:Label ID="lblTB5" runat="server" 

Width="349px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px">
                    <span style="font-family: Arial">TB6: &nbsp;&nbsp; 

&nbsp; &nbsp;</span><asp:TextBox
                        ID="TB6" runat="server" BackColor="LightGray" 

ForeColor="Black"
                        Width="183px" ToolTip="i.e. 

XXX1234"></asp:TextBox>
                    <asp:Label ID="lblTB6" runat="server" 

Width="348px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px">
                </td>
            </tr>
            
        Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub btnExit_Click(ByVal sender As Object, ByVal e 

As System.EventArgs) Handles BExit.Click
        Dim strscript As String = "<script 

language=javascript>window.top.close();</script>"
        If (Not 

ClientScript.IsStartupScriptRegistered("clientScript")) Then
            ClientScript.RegisterStartupScript(Page.GetType(), 

"clientScript", strscript)
        End If
    End Sub
    Protected Function ValidateTB1 (ByRef txt As String) As 

Boolean
        Dim reg As New Regex("^[A-Z]{2}[0-9]{4}$")
        Return (reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB2 (ByRef txt As String) As 

Boolean
        Dim reg As New Regex("^[0]{3}[0-9]{7}$")
        Return (reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB4 (ByRef txt As String) As 

Boolean
        Dim Reg As New Regex("^[0]{2}[0-9]{8}$")
        Return (Reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB6 (ByRef txt As String) As 

Boolean
        Dim reg As New Regex("^[A-Z]{3}[0-9]{4}$")
        Return (reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB3 (ByRef txt As String) As 

Boolean
        Dim Reg As New Regex("^[0-9]{10}$")
        Return (Reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB5 (ByRef txt As String) As 

Boolean
        Dim Reg As New Regex("^[0-9]{6}$")
        Return (Reg.IsMatch(txt))
    End Function
   
    
    Protected Sub BSubmit_Click(ByVal sender As Object, ByVal e 

As System.EventArgs) Handles BSubmit.Click

        Dim Validated As Boolean

        'validate TB1
        TB1.Text = TB1.Text.ToUpper()
        Validated = ValidateTB1(TB1.Text)
        If Not Validated Then
            lblTB1.Text = ("<span style='color: red'>Error 

message</span>")
           
            Exit Sub
        End If


        'validate TB2

        Validated = ValidateTB2(TB2.Text)

        If Not Validated Then
            lblTB2.Text = ("<span style='color: red'>Error 

Message</span>")
           
            Exit Sub

        End If

        'Validate RadioButtonList1

        If RadioButtonList1.SelectedIndex = -1 Then
            lblrbl1.Text = ("<span style='color: red'>Please select an 

option</span>")
          
        End If

        'Validate RadioButtonList2

        If RadioButtonList2.SelectedIndex = -1 Then
            lblrbl2.Text = ("<span style='color: red'>Please select an 

option</span>")
          
            Exit Sub
        End If

        'Validate DropDownlist   

        If RadioButtonList2.SelectedValue = "1" Then
            If DropDownList1.SelectedIndex = 0 Then
                lblproduct.Text = ("<span style='color: red'>Error 

Message</span>")
            
                Exit Sub
            End If
        End If

        If RadioButtonList2.SelectedValue = "2" Then
            If DropDownList2.SelectedIndex = 0 Then
                lblproduct2.Text = ("<span style='color: red'>Error 

Message</span>")
          
                Exit Sub
            End If
        End If

        'Validate TB6

        TB6.Text = TB6.Text.ToUpper()
        Validated = ValidateTB6(TB6.Text)

        If Not Validated Then
            lblTB6.Text = ("<span style='color:red'>Error 

Message</span>")
          
            Exit Sub
        End If

        'Validate TB3  

        Validated = ValidateTB3(TB3.Text)

        If TB3.Text <> "" Then
            If Not Validated Then
                lblTB3.Text = ("<span style='color:red'>Error 

Message</span>")
           
                Exit Sub
            End If
        End If

        'Validate TB4

        Validated = ValidateTB4(TB4.Text)

        If TB4.Text <> "" Then
            If Not Validated Then
                lblTB4.Text = ("<span style='color:red'>Error 

Message</span>")
           
            End If
        End If


        'Validate TB5

        Validated = ValidateTB5(TB5.Text)

        If TB5.Text <> "" Then
            If Not Validated Then
                lblTB5.Text = ("<span style='color:red'>Error 

Message</span>")
       
            End If
        End If




        'Open connection string and insert data into the 

service_Tracking database, ABM Coupon Data table
        Dim ConnectionString As String
        Dim Connection As SqlConnection
        Dim Adapter As New SqlDataAdapter
        Dim sql As String

        ConnectionString = "Data Source=00.0.00.00;Initial 

Catalog=Service_Tracking;User ID=example;pwd=example;"
        Connection = New SqlConnection(ConnectionString)

        If RadioButtonList1.SelectedValue = Option 1" Then

            If RadioButtonList2.SelectedValue = "1" Then

                sql = "insert into Table(table fields) VALUES (textbox 

values);"

            ElseIf RadioButtonList2.SelectedValue = "2" Then

                sql = "insert into Table(Table Fields) VALUES (textbox 

values);"

            End If

        ElseIf RadioButtonList1.SelectedValue = "Option 2" Then

            If RadioButtonList2.SelectedValue = "1 Then" Then

                sql = "insert into Table (Table Fields) VALUES (textbox 

Values);"

            ElseIf RadioButtonList2.SelectedValue = "2" Then

                sql = "insert into Table (Table Fields) VALUES (Textbox 

values);"

            End If

        End If

        Try
            Connection.Open()
            Adapter.InsertCommand = New SqlCommand(sql, 

Connection)
            Adapter.InsertCommand.ExecuteNonQuery()
            Response.Write("<span style='color: green'>Data 

Submitted</span>")

            

        Catch ex As Exception
            Response.Write("<span style='color: red'>Data Not 

Submitted</span>")
        End Try
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As 

System.EventArgs) Handles Me.Load
        lbldate.Text = Format(Date.Today.Date, "MMMM dd, yyyy")
    End Sub
End Class

            
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px; 

text-align: center">
                    <asp:Button ID="BSubmit" runat="server" 

Text="Submit" Width="74px" />
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

&nbsp; &nbsp;
                    <asp:Button ID="BExit" runat="server" Text="Exit" 

Width="67px" /></td>
            </tr>
        </table>
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label" 

Width="176px"></asp:Label><br />
        <br />
        &nbsp;</div>
    </form>
</body>
</html> 

Open in New WindowSelect All

Open in new window


VB.NET
 
<%@ Page Language="VB" AutoEventWireup="false" 

CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
    
     <script language="Javascript">
      <!--
         function isNumberKey(evt) {
             var charCode = (evt.which) ? evt.which : event.keyCode
             if (charCode > 31 && (charCode < 48 || charCode > 57))
                 return false;

             return true;
         }
      //-->
    </script>

    <script language="JavaScript">
<!--
        window.history.forward(1); //-->
    </script>
    
</head>
<body>
    <form id="form1" runat="server" autocomplete="off">
    <div>
        <table style="width: 700px; height: 100px; text-align: left">
            <tr>
                <td colspan="5" style="width: 3992px; height: 61px">
                    <span style="font-size: 24pt"><span style="color: 

#660033"><strong>TESTING</strong></span> 
                        &nbsp;&nbsp;
                    </span></td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px; height: 17px">
                </td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px; height: 21px">
                    <span style="font-family: Arial">Date: &nbsp; &nbsp; 

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

&nbsp; &nbsp; &nbsp;
                        <asp:Label ID="lbldate" runat="server" 

Width="161px"></asp:Label></span></td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px">
                    <span style="font-family: Arial">Tb1: &nbsp; &nbsp; 

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

&nbsp;&nbsp; </span>&nbsp;<asp:TextBox ID="TB1" 

runat="server" BackColor="LightGray" ForeColor="Black" 

MaxLength="6" ToolTip="i.e. XX1234"></asp:TextBox>
                    <asp:Label ID="lblTb1" runat="server" 

Width="352px" BorderColor="Red" Font-Bold="True" 

Font-Names="Arial" Font-Size="Smaller" 

ForeColor="Red"></asp:Label></td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px; height: 6px">
                    <span style="font-family: Arial">Tb2: &nbsp; &nbsp; 

&nbsp; &nbsp; &nbsp; &nbsp;
                        &nbsp; &nbsp; &nbsp; 

</span>&nbsp;<asp:TextBox
                        ID="Tb2" runat="server" onkeypress="return 

isNumberKey(event)" BackColor="LightGray" 

ForeColor="Black" MaxLength="10" ToolTip="i.e. 

0001234567"></asp:TextBox>
                    <asp:Label ID="lblTb2" runat="server" 

Width="358px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label></td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px; height: 15px">
                    <br />
                </td>
            </tr>
            <tr style="font-size: 12pt">
                <td colspan="5" style="width: 3992px; height: 27px">
                    <asp:RadioButtonList ID="RadioButtonList1" 

runat="server" Font-Names="Arial" 

RepeatDirection="Horizontal"
                        Width="335px">
                        <asp:ListItem Value="Option 1"></asp:ListItem>
                        <asp:ListItem Value="Option 2"></asp:ListItem>
                    </asp:RadioButtonList><asp:Label ID="lblrbl1" 

runat="server" Width="333px" Font-Bold="True" 

Font-Names="Arial" Font-Size="Smaller" 

ForeColor="Red"></asp:Label>&nbsp;
                   
</td>
            </tr>
            <tr style="font-family: Arial TUR; font-size: 12pt;">
                <td colspan="5" style="width: 3992px; height: 28px">
                </td>
            </tr>
            <tr style="font-family: Arial TUR; font-size: 12pt;">
                <td colspan="5" style="width: 3992px; height: 39px; 

border-top-style: solid; border-top-color: #660033;" 

bordercolor="#000000" bordercolorlight="#330033">
                    <span><span style="font-size: 16pt; font-family: 

Arial Baltic">PRODUCT INFORMATION:</span></span></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px" 

bordercolor="#000000" bordercolorlight="#330033">
                    <asp:RadioButtonList ID="RadioButtonList2" 

runat="server" Font-Names="Arial" 

RepeatDirection="Horizontal"
                        Width="600px">
                        <asp:ListItem Value="1">Option 3</asp:ListItem>
                        <asp:ListItem Value="2">Option 4</asp:ListItem>
                    </asp:RadioButtonList><asp:Label ID="lblrbl2" 

runat="server" Width="600px" Font-Bold="True" 

Font-Names="Arial" Font-Size="Smaller" 

ForeColor="Red"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 48px; 

border-bottom-color: #660033; border-bottom-style: solid;" 

bordercolor="#000000" bordercolorlight="#330033">

                    <asp:DropDownList ID="DropDownList1" 

runat="server" Width="165px" 

onchange="setEnabledTextBoxes(this);">
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem Text ="A" 

Value="A"></asp:ListItem>
                        <asp:ListItem Text = "B" 

Value="B"></asp:ListItem>
                        <asp:ListItem Text = "C" 

Value="C"></asp:ListItem>
                        <asp:ListItem Text = "D" 

Value="D"></asp:ListItem>
                  </asp:DropDownList>
                   <script language="javascript">

                       function enableListItem() {
                           form1.DropDownList1.enabled = true;
                       }


                       function setEnabledTextBoxes(ddl) {
                           switch (ddl.value) {
                               case "A":
                               case "B":
                               case "C":
                                   document.getElementById("TB3").disabled 

= false;
                                   document.getElementById("TB4").disabled 

= true;
                                   break;
                               case "D":
                               case "E":
                                   document.getElementById("TB3").disabled 

= true;
                                   document.getElementById("TB4").disabled 

= false;
                                   break;
                               default:
                                   break;
                           }
                       }
</script>

                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                    &nbsp;<asp:DropDownList ID="DropDownList2" 

runat="server" Width="165px" AutoPostBack="true" 

onselectedindexchanged="DropDownList1_SelectedIndexChang

ed">
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem Text = "1" 

Value="1"></asp:ListItem>
                        <asp:ListItem Text = "2" 

Value="2"></asp:ListItem>
                        <asp:ListItem Text = "3" 

Value="3"></asp:ListItem>
                        <asp:ListItem Text = "4" 

Value="4"></asp:ListItem>
                        
                    </asp:DropDownList>&nbsp;<br />
                    <asp:Label ID="lblproduct" runat="server" 

Width="247px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label>
                    &nbsp;&nbsp; &nbsp;<asp:Label ID="lblproduct2" 

runat="server" Width="261px" Font-Bold="True" 

Font-Names="Arial" Font-Size="Smaller" 

ForeColor="Red"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px">
                </td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px">
                    <span style="font-family: Arial TUR">Tb3:</span>
                    <asp:TextBox ID="TB3" runat="server" 

onkeypress="return isNumberKey(event)" 

BackColor="LightGray" ForeColor="Black "
                        Width="180px" MaxLength="10" 

Enabled="False"></asp:TextBox>
                    <asp:Label ID="lblTB3" runat="server" 

Width="352px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px">
                    <span style="font-family: Arial">TB4: &nbsp;<span 

style="font-family: Times New Roman">
                        &nbsp; &nbsp;&nbsp; </span></span> 

<asp:TextBox ID="TB4" runat="server" onkeypress="return 

isNumberKey(event)" BackColor="LightGray"
                        ForeColor="Black" Width="182px" 

MaxLength="10" Enabled="False"></asp:TextBox>
                    <asp:Label ID="lblTB4" runat="server" 

Width="352px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label></td>
            </tr>
            <tr style="font-family: Times New Roman">
                <td colspan="5" style="width: 3992px; height: 28px">
                    <span style="font-family: Arial">TB5: 

</span>&nbsp; &nbsp;&nbsp;
                    <asp:TextBox ID="TB5" runat="server" 

onkeypress="return isNumberKey(event)" 

BackColor="LightGray" ForeColor="Black"
                        Width="183px" MaxLength="10" 

Enabled="False"></asp:TextBox>
                    <asp:Label ID="lblTB5" runat="server" 

Width="349px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px">
                    <span style="font-family: Arial">TB6: &nbsp;&nbsp; 

&nbsp; &nbsp;</span><asp:TextBox
                        ID="TB6" runat="server" BackColor="LightGray" 

ForeColor="Black"
                        Width="183px" ToolTip="i.e. 

XXX1234"></asp:TextBox>
                    <asp:Label ID="lblTB6" runat="server" 

Width="348px" Font-Bold="True" Font-Names="Arial" 

Font-Size="Smaller" ForeColor="Red"></asp:Label></td>
            </tr>
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px">
                </td>
            </tr>
            
        Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub btnExit_Click(ByVal sender As Object, ByVal e 

As System.EventArgs) Handles BExit.Click
        Dim strscript As String = "<script 

language=javascript>window.top.close();</script>"
        If (Not 

ClientScript.IsStartupScriptRegistered("clientScript")) Then
            ClientScript.RegisterStartupScript(Page.GetType(), 

"clientScript", strscript)
        End If
    End Sub
    Protected Function ValidateTB1 (ByRef txt As String) As 

Boolean
        Dim reg As New Regex("^[A-Z]{2}[0-9]{4}$")
        Return (reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB2 (ByRef txt As String) As 

Boolean
        Dim reg As New Regex("^[0]{3}[0-9]{7}$")
        Return (reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB4 (ByRef txt As String) As 

Boolean
        Dim Reg As New Regex("^[0]{2}[0-9]{8}$")
        Return (Reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB6 (ByRef txt As String) As 

Boolean
        Dim reg As New Regex("^[A-Z]{3}[0-9]{4}$")
        Return (reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB3 (ByRef txt As String) As 

Boolean
        Dim Reg As New Regex("^[0-9]{10}$")
        Return (Reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB5 (ByRef txt As String) As 

Boolean
        Dim Reg As New Regex("^[0-9]{6}$")
        Return (Reg.IsMatch(txt))
    End Function
   
    
    Protected Sub BSubmit_Click(ByVal sender As Object, ByVal e 

As System.EventArgs) Handles BSubmit.Click

        Dim Validated As Boolean

        'validate TB1
        TB1.Text = TB1.Text.ToUpper()
        Validated = ValidateTB1(TB1.Text)
        If Not Validated Then
            lblTB1.Text = ("<span style='color: red'>Error 

message</span>")
           
            Exit Sub
        End If


        'validate TB2

        Validated = ValidateTB2(TB2.Text)

        If Not Validated Then
            lblTB2.Text = ("<span style='color: red'>Error 

Message</span>")
           
            Exit Sub

        End If

        'Validate RadioButtonList1

        If RadioButtonList1.SelectedIndex = -1 Then
            lblrbl1.Text = ("<span style='color: red'>Please select an 

option</span>")
          
        End If

        'Validate RadioButtonList2

        If RadioButtonList2.SelectedIndex = -1 Then
            lblrbl2.Text = ("<span style='color: red'>Please select an 

option</span>")
          
            Exit Sub
        End If

        'Validate DropDownlist   

        If RadioButtonList2.SelectedValue = "1" Then
            If DropDownList1.SelectedIndex = 0 Then
                lblproduct.Text = ("<span style='color: red'>Error 

Message</span>")
            
                Exit Sub
            End If
        End If

        If RadioButtonList2.SelectedValue = "2" Then
            If DropDownList2.SelectedIndex = 0 Then
                lblproduct2.Text = ("<span style='color: red'>Error 

Message</span>")
          
                Exit Sub
            End If
        End If

        'Validate TB6

        TB6.Text = TB6.Text.ToUpper()
        Validated = ValidateTB6(TB6.Text)

        If Not Validated Then
            lblTB6.Text = ("<span style='color:red'>Error 

Message</span>")
          
            Exit Sub
        End If

        'Validate TB3  

        Validated = ValidateTB3(TB3.Text)

        If TB3.Text <> "" Then
            If Not Validated Then
                lblTB3.Text = ("<span style='color:red'>Error 

Message</span>")
           
                Exit Sub
            End If
        End If

        'Validate TB4

        Validated = ValidateTB4(TB4.Text)

        If TB4.Text <> "" Then
            If Not Validated Then
                lblTB4.Text = ("<span style='color:red'>Error 

Message</span>")
           
            End If
        End If


        'Validate TB5

        Validated = ValidateTB5(TB5.Text)

        If TB5.Text <> "" Then
            If Not Validated Then
                lblTB5.Text = ("<span style='color:red'>Error 

Message</span>")
       
            End If
        End If




        'Open connection string and insert data into the 

service_Tracking database, ABM Coupon Data table
        Dim ConnectionString As String
        Dim Connection As SqlConnection
        Dim Adapter As New SqlDataAdapter
        Dim sql As String

        ConnectionString = "Data Source=00.0.00.00;Initial 

Catalog=Service_Tracking;User ID=example;pwd=example;"
        Connection = New SqlConnection(ConnectionString)

        If RadioButtonList1.SelectedValue = Option 1" Then

            If RadioButtonList2.SelectedValue = "1" Then

                sql = "insert into Table(table fields) VALUES (textbox 

values);"

            ElseIf RadioButtonList2.SelectedValue = "2" Then

                sql = "insert into Table(Table Fields) VALUES (textbox 

values);"

            End If

        ElseIf RadioButtonList1.SelectedValue = "Option 2" Then

            If RadioButtonList2.SelectedValue = "1 Then" Then

                sql = "insert into Table (Table Fields) VALUES (textbox 

Values);"

            ElseIf RadioButtonList2.SelectedValue = "2" Then

                sql = "insert into Table (Table Fields) VALUES (Textbox 

values);"

            End If

        End If

        Try
            Connection.Open()
            Adapter.InsertCommand = New SqlCommand(sql, 

Connection)
            Adapter.InsertCommand.ExecuteNonQuery()
            Response.Write("<span style='color: green'>Data 

Submitted</span>")

            

        Catch ex As Exception
            Response.Write("<span style='color: red'>Data Not 

Submitted</span>")
        End Try
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As 

System.EventArgs) Handles Me.Load
        lbldate.Text = Format(Date.Today.Date, "MMMM dd, yyyy")
    End Sub
End Class

            
            <tr>
                <td colspan="5" style="width: 3992px; height: 28px; 

text-align: center">
                    <asp:Button ID="BSubmit" runat="server" 

Text="Submit" Width="74px" />
                    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 

&nbsp; &nbsp;
                    <asp:Button ID="BExit" runat="server" Text="Exit" 

Width="67px" /></td>
            </tr>
        </table>
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label" 

Width="176px"></asp:Label><br />
        <br />
        &nbsp;</div>
    </form>
</body>
</html> 

Open in New WindowSelect All

Open in new window

Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub btnExit_Click(ByVal sender As Object, ByVal e 

As System.EventArgs) Handles BExit.Click
        Dim strscript As String = "<script 

language=javascript>window.top.close();</script>"
        If (Not 

ClientScript.IsStartupScriptRegistered("clientScript")) Then
            ClientScript.RegisterStartupScript(Page.GetType(), 

"clientScript", strscript)
        End If
    End Sub
    Protected Function ValidateTB1 (ByRef txt As String) As 

Boolean
        Dim reg As New Regex("^[A-Z]{2}[0-9]{4}$")
        Return (reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB2 (ByRef txt As String) As 

Boolean
        Dim reg As New Regex("^[0]{3}[0-9]{7}$")
        Return (reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB4 (ByRef txt As String) As 

Boolean
        Dim Reg As New Regex("^[0]{2}[0-9]{8}$")
        Return (Reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB6 (ByRef txt As String) As 

Boolean
        Dim reg As New Regex("^[A-Z]{3}[0-9]{4}$")
        Return (reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB3 (ByRef txt As String) As 

Boolean
        Dim Reg As New Regex("^[0-9]{10}$")
        Return (Reg.IsMatch(txt))
    End Function
    Protected Function ValidateTB5 (ByRef txt As String) As 

Boolean
        Dim Reg As New Regex("^[0-9]{6}$")
        Return (Reg.IsMatch(txt))
    End Function
   
    
    Protected Sub BSubmit_Click(ByVal sender As Object, ByVal e 

As System.EventArgs) Handles BSubmit.Click

        Dim Validated As Boolean

        'validate TB1
        TB1.Text = TB1.Text.ToUpper()
        Validated = ValidateTB1(TB1.Text)
        If Not Validated Then
            lblTB1.Text = ("<span style='color: red'>Error 

message</span>")
           
            Exit Sub
        End If


        'validate TB2

        Validated = ValidateTB2(TB2.Text)

        If Not Validated Then
            lblTB2.Text = ("<span style='color: red'>Error 

Message</span>")
           
            Exit Sub

        End If

        'Validate RadioButtonList1

        If RadioButtonList1.SelectedIndex = -1 Then
            lblrbl1.Text = ("<span style='color: red'>Please select an 

option</span>")
          
        End If

        'Validate RadioButtonList2

        If RadioButtonList2.SelectedIndex = -1 Then
            lblrbl2.Text = ("<span style='color: red'>Please select an 

option</span>")
          
            Exit Sub
        End If

        'Validate DropDownlist   

        If RadioButtonList2.SelectedValue = "1" Then
            If DropDownList1.SelectedIndex = 0 Then
                lblproduct.Text = ("<span style='color: red'>Error 

Message</span>")
            
                Exit Sub
            End If
        End If

        If RadioButtonList2.SelectedValue = "2" Then
            If DropDownList2.SelectedIndex = 0 Then
                lblproduct2.Text = ("<span style='color: red'>Error 

Message</span>")
          
                Exit Sub
            End If
        End If

        'Validate TB6

        TB6.Text = TB6.Text.ToUpper()
        Validated = ValidateTB6(TB6.Text)

        If Not Validated Then
            lblTB6.Text = ("<span style='color:red'>Error 

Message</span>")
          
            Exit Sub
        End If

        'Validate TB3  

        Validated = ValidateTB3(TB3.Text)

        If TB3.Text <> "" Then
            If Not Validated Then
                lblTB3.Text = ("<span style='color:red'>Error 

Message</span>")
           
                Exit Sub
            End If
        End If

        'Validate TB4

        Validated = ValidateTB4(TB4.Text)

        If TB4.Text <> "" Then
            If Not Validated Then
                lblTB4.Text = ("<span style='color:red'>Error 

Message</span>")
           
            End If
        End If


        'Validate TB5

        Validated = ValidateTB5(TB5.Text)

        If TB5.Text <> "" Then
            If Not Validated Then
                lblTB5.Text = ("<span style='color:red'>Error 

Message</span>")
       
            End If
        End If




        'Open connection string and insert data into the 

service_Tracking database, ABM Coupon Data table
        Dim ConnectionString As String
        Dim Connection As SqlConnection
        Dim Adapter As New SqlDataAdapter
        Dim sql As String

        ConnectionString = "Data Source=00.0.00.00;Initial 

Catalog=Service_Tracking;User ID=example;pwd=example;"
        Connection = New SqlConnection(ConnectionString)

        If RadioButtonList1.SelectedValue = Option 1" Then

            If RadioButtonList2.SelectedValue = "1" Then

                sql = "insert into Table(table fields) VALUES (textbox 

values);"

            ElseIf RadioButtonList2.SelectedValue = "2" Then

                sql = "insert into Table(Table Fields) VALUES (textbox 

values);"

            End If

        ElseIf RadioButtonList1.SelectedValue = "Option 2" Then

            If RadioButtonList2.SelectedValue = "1 Then" Then

                sql = "insert into Table (Table Fields) VALUES (textbox 

Values);"

            ElseIf RadioButtonList2.SelectedValue = "2" Then

                sql = "insert into Table (Table Fields) VALUES (Textbox 

values);"

            End If

        End If

        Try
            Connection.Open()
            Adapter.InsertCommand = New SqlCommand(sql, 

Connection)
            Adapter.InsertCommand.ExecuteNonQuery()
            Response.Write("<span style='color: green'>Data 

Submitted</span>")

            

        Catch ex As Exception
            Response.Write("<span style='color: red'>Data Not 

Submitted</span>")
        End Try
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As 

System.EventArgs) Handles Me.Load
        lbldate.Text = Format(Date.Today.Date, "MMMM dd, yyyy")
    End Sub
End Class

Open in new window

0
 
LVL 7

Expert Comment

by:m4trix
ID: 35733576
unfortunately I do not know much at all about .NET, so how exactly it all works I'm not sure. I would imagine there must be a way to pass the state of the textbox back via vb script so that it "remembers" its setting. Sorry I can't help further!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

831 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