通过asp.net控件修改css显示

时间:2013-01-06 06:13:17

标签: asp.net css vb.net-2010

好的,所以我试着让一个下拉菜单取消隐藏我选择特定索引时隐藏的一些div。我知道内联样式需要更改,但不知道如何使用背面控件来执行它。

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master"
CodeBehind="Estimation.aspx.vb" Inherits="CIS212FinalProjectASPportion.WebForm1" %>
<body Id="mainBody" runat="server">
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="EstimationSelection">
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                <asp:ListItem>Select Value</asp:ListItem>
                <asp:ListItem>Lawn Care</asp:ListItem>
                <asp:ListItem>Plowing</asp:ListItem>
                <asp:ListItem>Both</asp:ListItem>
            </asp:DropDownList>
            <br />
</div>

<div id="UserInfo" style="display: none;">
    <asp:Label ID="firstName" runat="server" Text="Label">First Name &nbsp;</asp:Label>
    <input id="Text1" type="text" />
    <asp:Label ID="lastName" runat="server" Text="Label">Last Name &nbsp;</asp:Label>
    <input id="Text2" type="text" /> <br />
    <asp:Label ID="address" runat="server" Text="Label">Address       &nbsp&nbsp;&nbsp;&nbsp;&nbsp;</asp:Label>
    <input id="Text3" type="text" />
    <asp:Label ID="city" runat="server" Text="Label">City &nbsp;</asp:Label>
    <input id="Text4" type="text" /><br />
    <asp:Label ID="state" runat="server" Text="Label">State&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</asp:Label>
    <input id="Text5" type="text" />
    <asp:Label ID="zipCode" runat="server" Text="Label">Zip Code &nbsp;</asp:Label>
    <input id="Text6" type="text" /> <br />
    <asp:Label ID="emailAddress" runat="server" Text="Label">Email Address &nbsp;</asp:Label>
    <input id="Text7" type="text" />
</div>
</body>
</asp:Content>

然后现在我的背面代码

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
    If DropDownList1.SelectedIndex(1) Then
         Me.Body.Div.UserInfo.Style.add("display", "block")
        ' set div id="LawnCare" style="display: block;"
    End If
End Sub

选项Explicit和Strict都打开。

1 个答案:

答案 0 :(得分:0)

尝试这样..........

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
  Dim oPanel As Panel
  oPanel = Me.FindControl("UserInfo")
  If DropDownList1.SelectedIndex = 1 Then
    oPanel.Visible = True
  Else
    oPanel.Visible = False
  End If
  oPanel = Nothing
End Sub


<div id="EstimationSelection">
  <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
    <asp:ListItem>Select Value</asp:ListItem>
    <asp:ListItem>Lawn Care</asp:ListItem>
    <asp:ListItem>Plowing</asp:ListItem>
    <asp:ListItem>Both</asp:ListItem>
  </asp:DropDownList>
  <br />
</div>

<asp:Panel id="UserInfo" Visible="false" runat="server">
  <asp:Label ID="firstName" runat="server" Text="Label">First Name</asp:Label>
    <input id="Text1" type="text" />
  <asp:Label ID="lastName" runat="server" Text="Label">Last Name</asp:Label>
    <input id="Text2" type="text" /> <br />
  <asp:Label ID="address" runat="server" Text="Label">Address</asp:Label>
    <input id="Text3" type="text" />
  <asp:Label ID="city" runat="server" Text="Label">City</asp:Label>
    <input id="Text4" type="text" /><br />
  <asp:Label ID="state" runat="server" Text="Label">State</asp:Label>
    <input id="Text5" type="text" />
  <asp:Label ID="zipCode" runat="server" Text="Label">Zip Code</asp:Label>
    <input id="Text6" type="text" /> <br />
  <asp:Label ID="emailAddress" runat="server" Text="Label">Email Address</asp:Label>
    <input id="Text7" type="text" />
</asp:Panel>

基本上我将客户端DIV更改为服务器端PANEL