无法获取多视图控件来更改视图

本文关键字:视图 控件 获取 | 更新日期: 2023-09-27 18:34:50

我有一个多视图控件,它有两个视图。View1 是默认视图,View2 是新视图。当最终用户单击按钮时,我想将视图更改为 View2。反正我去,我似乎都做不到这个目标。

ASP.NET 代码:

<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>

按钮单击事件代码:

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

页面加载代码:

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

有人可以告诉我我做错了什么吗?

无法获取多视图控件来更改视图

我认为您可能有一些额外的代码可能会使其无法正常工作。但根据您显示的内容,这将发布并更新您的视图:

<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>