首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP错误,无法解决这个问题

ASP错误,无法解决这个问题
EN

Stack Overflow用户
提问于 2016-11-07 02:51:56
回答 1查看 32关注 0票数 0

所以我得到了一个典型的错误:

调用Sub时不能使用括号

在我的网页上执行这段代码的时候。

以下是代码:

代码语言:javascript
复制
 <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
    %>

基本上,我试图根据用户从我的HTML下拉菜单中选择的选项来更改页面的背景。我不明白我做错了什么。

EN

回答 1

Stack Overflow用户

发布于 2016-11-07 05:49:56

aspx文件代码

代码语言:javascript
复制
<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码

代码语言:javascript
复制
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

看起来不错

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40457118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档