0

So I am getting the classic error:

Cannot use parentheses when calling a Sub

when trying to execute this code on my webpage.

Here is the code:

 <select class=<% Response.write("""" & colour & " ")%> selection" name="col" id="chosen">
          <option value="none" selected disabled>---</option>
          <option value="red">Red</option>
          <option value="blue">Blue</option>
          <option value="green">Green</option>
        </select>
      </div>
      <br>
      <input type="submit" class=<% Response.write("""" & colour & " ")%> btn" value="This one!">
    </form>
    <%
    if chosen.value = Red then PageBody.Attributes.Add("bgcolor", "red")
    elseif chosen.value = Blue then PageBody.Attributes.Add("bgcolor", "blue")
    elseif chosen.value = Green then PageBody.Attributes.Add("bgcolor", "green")
    end if
    %>

Basically I am trying to change the background of the page depending on the option the user chooses from my HTML dropdown menu. I don't understand what I am doing wrong.

David Tansey
  • 5,813
  • 4
  • 35
  • 51
  • 1
    regarding to your issue, you might want to read this post http://stackoverflow.com/questions/14902134/cannot-use-parentheses-when-calling-a-sub-error-800a0414-vbs/14908329 – Bukhari Nov 07 '16 at 03:51

1 Answers1

0

aspx file code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server" >
        <asp:DropDownList ID="chosen1" runat="server" OnSelectedIndexChanged="chosen1_SelectedIndexChanged" AutoPostBack="true">
          <asp:ListItem Value="none" Selected="True">---</asp:ListItem>
           <asp:ListItem Value="red">Red</asp:ListItem>
           <asp:ListItem Value="blue">Blue</asp:ListItem>
           <asp:ListItem Value="green">Green</asp:ListItem>
        </asp:DropDownList>
    </form>

</body>
</html>

aspx.cs Code

Protected Sub Page_Load(sender As Object, e As EventArgs)

End Sub

Protected Sub chosen1_SelectedIndexChanged(sender As Object, e As EventArgs)
    If chosen1.SelectedIndex <> 0 Then
        Dim color = chosen1.SelectedValue.ToString()

        form1.Attributes.CssStyle.Add("background-color", color)
    End If
End Sub

It will work