C#Multiview持久数据

时间:2015-11-20 10:38:21

标签: c# multiview

我目前在网络表单用户控制页面中使用多视图控件,在视图之间导航,我们的数据不会持续存在。

三个视图,最后一个视图包含前两个视图中输入内容的摘要,如果我点击摘要视图,则可以从秒视图中获取数据。

在视图之间来回点击,我们的表单数据会丢失。

任何想法从哪里开始?

.ascx 页面

    <asp:MultiView ID="MultiView1" ActiveViewIndex="0" EnableViewState="true" runat="server">
    <asp:View ID="View1" runat="server">
        Name:<br />
        <asp:TextBox ID="txtName" runat="server" />
    </asp:View>
    <asp:View ID="View2" runat="server">
        Surname:<br />
        <asp:TextBox ID="txtSurname" runat="server" />
    </asp:View>
    <asp:View ID="View3" runat="server">
        <b>Summary</b><br />
        Name:
        <asp:Label ID="lblName" runat="server" /><br />
        Surname:
        <asp:Label ID="lblSurname" runat="server" /><br />
    </asp:View>
</asp:MultiView>
<asp:Button ID="btnBack" runat="server" Text="&lt; Back " OnClick="btnBack_Click" />
<asp:Button ID="btnNext" runat="server" Text="Next &gt;" OnClick="btnNext_Click" />
<asp:Button ID="btnSend" runat="server" Text="Submit" OnClick="btnSend_Click" />

ascx.cs Codebehind

    protected void btnBack_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex--;
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex++;
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
    }
    protected override void OnPreRender(EventArgs e)
    {
        if (MultiView1.ActiveViewIndex == MultiView1.Views.Count - 1)
        {
            FillSummary();
        }
        btnBack.Visible = MultiView1.ActiveViewIndex > 0;
        btnNext.Visible = MultiView1.ActiveViewIndex < MultiView1.Views.Count - 1;
        btnSend.Visible = MultiView1.ActiveViewIndex == MultiView1.Views.Count - 1;
        base.OnPreRender(e);
    }
    private void FillSummary()
    {
        lblName.Text = txtName.Text;
        lblSurname.Text = txtSurname.Text;
    }

0 个答案:

没有答案