C# asp.net如何更改asp:面板的颜色
我正在尝试更改web应用程序中C# asp.net如何更改asp:面板的颜色,c#,asp.net,panel,C#,Asp.net,Panel,我正在尝试更改web应用程序中面板的(背面)颜色,以表示模式更改。我正在使用一个asp.net WebForm项目,使用VS Express 2013 for Web。我有一个包含多个页面的web应用程序,其中一个页面包含一组三个嵌套面板: <asp:Panel ID="ManageTemplatesPanel" runat="server" style="border-radius:3px" BorderStyle="Solid" BackColor="White" Height="14
面板的(背面)颜色,以表示模式更改。我正在使用一个asp.net WebForm项目,使用VS Express 2013 for Web。我有一个包含多个页面的web应用程序,其中一个页面包含一组三个嵌套面板:
<asp:Panel ID="ManageTemplatesPanel" runat="server" style="border-radius:3px" BorderStyle="Solid" BackColor="White" Height="1415px" Width="930px" ScrollBars="None" BorderWidth="1px">
<asp:Panel ID="BigInsetGrayPanel" runat="server" style="border-radius:3px" BackColor="Silver" BorderStyle="Solid" BorderWidth="1px" Height="1275px" Width="910px" >
<asp:Panel ID="SelectClientsWhiteInsetPanel" runat="server" style="margin-left:20px;margin-right:20px;border-radius:3px" BackColor="White" Height="465px" BorderStyle="None">
这嵌套在“ManageTemplatesPanel”中。我已经创建了一个名为includeCheckBox列表的SelectedIndexChanged
事件处理程序。代码如下:
protected void IncludeCheckBoxList_SelectedIndexChanged(object sender, EventArgs e)
{
ListItemCollection items = IncludeCheckBoxList.Items;
foreach (ListItem item in items)
{
string section = item.Value;
bool itemChecked = item.Selected;
if (0 == String.Compare(section, "Sent Client List", true))
UpdateSentClientSection(itemChecked);
else if (0 == String.Compare(section, "Notification Time", true))
UpdateNotificationTimeSection(itemChecked);
else if (0 == String.Compare(section, "Message", true))
UpdateMessageSection(itemChecked);
}
}
以下是UpdateSentClientSection
的代码:
private void UpdateSentClientSection(bool itemChecked)
{
if (itemChecked)
MessageWhiteInsetPanel.BackColor = System.Drawing.Color.White;
else
MessageWhiteInsetPanel.BackColor = System.Drawing.Color.Blue;
}
我搜索过,有几篇博客建议用这种方式改变面板的背景色,但我无法让它工作。你知道为什么吗
提前感谢…由于您试图在服务器端事件期间修改元素,因此必须使用ajax面板并在方法UpdateSentClientSection中调用ajaxpanel.update()
请参阅:Update-出于某种原因,原始帖子没有包含“我的面板”和“复选框列表”定义:已经完成;)UpdatePanel(据我所知)用于防止页面或部分页面因回发而闪烁。这对我有什么帮助?这将对你有帮助,因为你必须再次发布页面以使颜色发生变化。由于“更新”面板将仅更新节,因此用户可以直接看到它。
private void UpdateSentClientSection(bool itemChecked)
{
if (itemChecked)
MessageWhiteInsetPanel.BackColor = System.Drawing.Color.White;
else
MessageWhiteInsetPanel.BackColor = System.Drawing.Color.Blue;
}