Can't get multiview control to change views

三世轮回 提交于 2020-01-15 06:36:18

问题


I have a multiview control, that has two views. View1 is the default view, and View2 is the new view. When the end user click a button, I want to change the view to View2. I can't seem to achieve this anyway I go.

ASP.NET Code:

<asp:MultiView ID="MVOrder" runat="server">
    <asp:View ID="VOrderNow" runat="server">
        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
            <ContentTemplate>
                <table>
                    <tr>
                        <td>
                        <asp:Label ID="LblInfo" runat="server"></asp:Label>
                        </td>
                        <td>
                        &nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                        <asp:Label ID="LblDrink" runat="server"></asp:Label>
                        </td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>
                        <asp:Label ID="LblItemInfo" runat="server"></asp:Label>
                        </td>
                        <td>
                        &nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
                <br />
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:View>
    <asp:View runat="server" ID="VOrderComplete">

    <table class="auto-style1">
        <tr>
            <td>&nbsp;</td>
            <td>
            <asp:Label ID="LblOrderComplete" runat="server"></asp:Label>
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>
            <asp:Label ID="LblOrderNumberAgain" runat="server"></asp:Label>
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>
            <asp:Label ID="LblOrderTimeAgain" runat="server"></asp:Label>
            </td>
            <td>&nbsp;</td>
        </tr>
    </table>

    </asp:View>
<br/>
</asp:MultiView>

Button Click Event Code:

protected void Button1_Click(object sender, EventArgs e)
        {
            //MVOrder.ActiveViewIndex = 1;
            MVOrder.SetActiveView(VOrderComplete);
        } 

Page Load Code:

if (!IsPostBack)
{
    MVOrder.SetActiveView(VOrderNow);
}

Can someone please tell me what I am doing wrong?


回答1:


I think you might have some additional code that might make this not work properly. But based on what you've shown, this will post and update your view:

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
        <asp:MultiView ID="MVOrder" runat="server">
            <asp:View ID="VOrderNow" runat="server">
                <table>
                    <tr>
                        <td><asp:Label ID="LblInfo" runat="server" Text="asdfasdfasdf"></asp:Label></td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td><asp:Label ID="LblDrink" runat="server" Text="lmnoplmnop"></asp:Label></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td><asp:Label ID="LblItemInfo" runat="server" Text="iteminfo"></asp:Label></td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
                <br />
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            </asp:View>
            <asp:View runat="server" ID="VOrderComplete">
                <table class="auto-style1">
                    <tr>
                        <td>&nbsp;</td>
                        <td><asp:Label ID="LblOrderComplete" runat="server" Text="ordercomplete"></asp:Label></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><asp:Label ID="LblOrderNumberAgain" runat="server" Text="ordernumberagain"></asp:Label></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><asp:Label ID="LblOrderTimeAgain" runat="server" Text="ordertimeagain"></asp:Label></td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
            </asp:View>
            <br />
        </asp:MultiView>
    </ContentTemplate>
</asp:UpdatePanel>


来源:https://stackoverflow.com/questions/27576631/cant-get-multiview-control-to-change-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!