-
Very Simple problem
Hi i don't know why the following doesn't work. I simply have a list of items in an array which i have bound to a dropdownlist.
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<script runat="server">
Sub Page_Load()
If NOT ispostback then
Dim ColorArray(4) as String
ColorArray(0) = "Blue"
ColorArray(1) = "Red"
ColorArray(2) = "Green"
ColorArray(3) = "Yellow"
ColorArray(4) = "Orange"
MyDropDownList.DataSource = ColorArray
MyDropDownList.DataBind()
End if
End Sub
Sub ColorSelected(Source as Object, E as EventArgs)
Dim MyColorText as String
MyColorText = MyDropDownList.SelectedItem.text
response.write (MyColorText)
End Sub
</script>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgColor="<%response.write(MyColorText)%>" >
<form runat="server">
<asp:dropdownlist ID="MyDropDownList" runat="server"></asp:dropdownlist>
<asp:button text="Hit Me" onCLick="ColorSelected" runat="server" />
</form>
</font>
</body>
</html>
Problem is here: bgColor="<%response.write(MyColorText)%>"
-
ok, you just need to move the line
Code:
Dim MyColorText as String
outside the Sub so that the variable is declared and available at the page level:
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<script runat="server">
Sub Page_Load()
If NOT ispostback then
Dim ColorArray(4) as String
ColorArray(0) = "Blue"
ColorArray(1) = "Red"
ColorArray(2) = "Green"
ColorArray(3) = "Yellow"
ColorArray(4) = "Orange"
MyDropDownList.DataSource = ColorArray
MyDropDownList.DataBind()
End if
End Sub
Dim MyColorText as String
Sub ColorSelected(Source as Object, E as EventArgs)
MyColorText = MyDropDownList.SelectedItem.text
response.write (MyColorText)
End Sub
</script>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgColor="<%response.write(MyColorText)%>" >
<form runat="server">
<asp:dropdownlist ID="MyDropDownList" runat="server"></asp:dropdownlist>
<asp:button text="Hit Me" onCLick="ColorSelected" runat="server" />
</form>
</font>
</body>
</html>
-
You can try this:
Code:
Sub ColorSelected(Source as Object, E as EventArgs)
response.write (MyDropDownList.SelectedItem.text)
End Sub