-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow and hide based on a text box.txt
57 lines (53 loc) · 2.16 KB
/
show and hide based on a text box.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Protected Sub btnFive_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFive.Click
Dim numberOf As Integer = 0
If String.IsNullOrEmpty(txtNumberOf.Text) = False Then 'Takes the value from a text box and stores it for the looping
Integer.TryParse(txtNumberOf.Text, numberOf)
If numberOf > -1 Then 'Allows zero to be an inputted value
showHideBoxes(numberOf)
End If
End If
End Sub
Private Sub showHideBoxes(ByVal num As Integer)
Dim c As Control
Dim i As Integer
'Loop 1 identifies and hides all boxes
For i = 1 To 9 'End Point is hard coded to total number of boxes we want to hide
c = Page.FindControl("TextBox" + i.ToString) 'Finds a control labeled Textbox1, and so on for the value of i
If TypeOf c Is TextBox Then 'Prevents the form from failing
c.Visible = False
End If
Next 'Continue to loop 2 to flip the desired number of boxes
If num > 0 Then
For i = 1 To num
c = Page.FindControl("TextBox" + i.ToString)
If TypeOf c Is TextBox Then
c.Visible = True
End If
Next
End If
End Sub
Private Sub readOnlyFlip(ByVal num As Integer)
Dim c As UI.WebControls.TextBox
Dim i As Integer
'Dim txtBox As Control
For i = 1 To 27 'This will change once we work out the math for determining the columns selected.
c = Page.FindControl("TextBox" + i.ToString)
'Dim txtBox = c, Type("TextBox")
If TypeOf c Is TextBox Then
'c.Attributes.Add("readonly", "readonly")
c.ReadOnly = True
c.BackColor = Drawing.Color.WhiteSmoke
End If
Next
If num > 0 Then
For i = 1 To num
c = Page.FindControl("TextBox" + i.ToString)
'Dim txtBox = c, Type("TextBox")
If TypeOf c Is TextBox Then
'c.Attributes.Add("readonly", "readonly")
c.ReadOnly = False
c.BackColor = Drawing.Color.White
End If
Next
End If
End Sub