.net C# MultiView制作tab 效果
前端如下:
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="Button" OnClick="Button2_Click" />
<asp:MultiView ID="MultiView2" runat="server" OnActiveViewChanged="MultiView1_ActiveViewChanged">
<asp:View ID="View1" runat="server">
<div id="view1_div">test1</div>
</asp:View>
<asp:View ID="View2" runat="server">
<div id="view2_div">test2</div>
</asp:View>
</asp:MultiView>
后端如下:
protected void Button2_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
if (b.ID == "Button2")
{
//激活View1
MultiView2.SetActiveView(View1);
Button2.BackColor = Color.AntiqueWhite;//View1 View2都设置了此背景色
Button3.BackColor = SystemColors.Control;//恢复控件本色
}
else
{
//激活View2
MultiView2.SetActiveView(View2);
Button2.BackColor = SystemColors.Control;
Button3.BackColor = Color.AntiqueWhite;
}
}
效果如下: