Hi,
I have a dropdownlist in
vb.net (server controls). Based on the user's selection from the list of items certain textboxes have to be disabled. I wrote a code but it only seems to work once the page is loaded (which is also what i need). I need it to work also after the page is loaded and a user selects an item.
I tried putting the code also in Private Sub List1_SelectedIndexChanged but it doesn't work
This is my code in codebehind (aspx.
vb):
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Dim li As New ListItem()
Dim cities(3) As String
cities(0) = "Pretoria"
cities(1) = "JHB"
cities(2) = "Benoni"
Dim i As Integer
For i = 0 To UBound(cities) - 1
List1.Items.Add(cities(i))
Next
End If
RegisterStartupScript("start", _
"<script>disableTextBox ();</script>")
End Sub
_______________________________
The code in aspx:
<script language="javascript">
function disableTextBox()
{
strSelectedItem = document.Form1.List1.options[document.Form1.List1.selectedIndex].text
if(strSelectedItem == "Pretoria")
{
document.Form1.Text1.disabled=true;
document.Form1.txt2.disabled =false;
}
else if(strSelectedItem == "Benoni")
{
document.Form1.txt2.disabled = true;
document.Form1.Text1.disabled=false;
}
}
</script>
</HEAD>