omerkamran
I would really like to understand the motivation for needing to show all views at the same time . Normally the views are mutually exclusive and thus you only see one at a time. If for you there is a scenario that requires showing all views simultaneously then maybe you should be using panels with hide/show on navigation and the possibility to 'Show all'. I have some code below which shows you how to achieve this in views but I would not recommend it and ideally ask you to change your design for incorporating this scenario. Anyways here goes...
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack && MultiView1.ActiveViewIndex == MultiView1.Views.Count - 1)
{
if (MultiView1.Views[MultiView1.ActiveViewIndex].Controls.Count == 1)
{
HydrateView();
}
}
}
private void HydrateView()
{
int k = 0;
for (int i = 0; i < MultiView1.Views.Count - 1; i++)
{
View x = (View)MultiView1.Views[i];
for (int j = 0; j < x.Controls.Count; j++)
{
Control c = x.Controls[j] as Panel;
if (c != null)
{
MultiView1.Views[MultiView1.ActiveViewIndex].Controls.AddAt(k, c);
k++;
}
}
}
}
protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
{
if (MultiView1.ActiveViewIndex == MultiView1.Views.Count-1) {
HydrateView();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = MultiView1.ActiveViewIndex - 1;
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = MultiView1.ActiveViewIndex +1;
}
protected void Button4_Click(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = MultiView1.Views.Count - 1;
}
<asp:MultiView ID="MultiView1" runat="server" OnActiveViewChanged="MultiView1_ActiveViewChanged" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></asp:Panel>
<asp:Button ID="Button2" runat="server" Text="Next" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="Show All" OnClick="Button4_Click" /></asp:View>
<asp:View ID="View2" runat="server">
<asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Item1</asp:ListItem>
<asp:ListItem>Item2</asp:ListItem>
<asp:ListItem>Item3</asp:ListItem>
</asp:DropDownList>
</asp:Panel>
<asp:Button ID="Button4" runat="server" Text="Previous" OnClick="Button3_Click" />
<asp:Button ID="Button5" runat="server" Text="Show All" OnClick="Button4_Click" /></asp:View>
<asp:View ID="AllView" runat="server">
</asp:View>
</asp:MultiView>
BobbyStrain
Спасибо вам за ваше решение. Это сложнее, чем я хотел бы осуществить. Моя цель состоит в том, чтобы сохранить информацию для каждого представления без нескольких сохранений страниц. Но реализация исправления-это уже слишком. Итак, пока я оставлю страницу такой, какая она есть, и позволю пользователю сохранить каждый вид или тот, который представляет интерес.