Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an ASP.NET page with 3 views in a multiview control. Is there a way to show all the views on a single page to save? I want to avoid users having to save each view as a separate page. I'm using .NET 4.

What I have tried:

I have searched for a solution, but find nothing satisfactory. There is some discussion on view state, but I don't understand how to use this to accomplish my objective.
Posted
Updated 28-May-17 21:34pm

As stated in the documentation it does not support this.
Only one View control at a time can be defined as active within a MultiView control. The View control that is set to the ActiveViewIndex property will be rendered to the client. If the ActiveViewIndex property is set to a View that does not exist within the MultiView control, a ArgumentOutOfRangeException is raised at run time. If the property is empty, the MultiView control does not render any content to the client.
 
Share this answer
 
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...
VB
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.NET
<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>
 
Share this answer
 
Comments
BobbyStrain 29-May-17 11:23am    
Thank you for your solution. It is more difficult than I wish to implement. My objective is to save the information for each view without multiple page saves. But implementing the fix is too much. So, for now, I will leave the page as it is and let the user save each view, or the one of interest.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900