如何将数据传递到另一个视图,ASP.NET

时间:2014-09-05 16:33:07

标签: c# asp.net

我想从view1中的某个文本框中传递一些值,并且在view2中需要这些值,我怎么能实现这一点。在view2中,我有用户控制器

UserForm.aspx

    <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
        <asp:View ID="View1" runat="server">
            <div style="height: 363px">

        <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>&nbsp;
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>&nbsp;
        <asp:RequiredFieldValidator ControlToValidate="txtName" Text="This field is required"
          ForeColor="Red" runat="server"><img src="Images/icon_error_white.gif" alt="Error" />         </asp:RequiredFieldValidator><br />
        <asp:Label ID="Label2" runat="server" Text="Phone"></asp:Label>&nbsp;
        <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>&nbsp
        <asp:RequiredFieldValidator ControlToValidate="txtPhone" Text="This field is required"
            ForeColor="Red" runat="server"><img src="Images/icon_error_white.gif" alt="Error" /></asp:RequiredFieldValidator><br />
        <asp:Label ID="Label3" runat="server" Text="Doc"></asp:Label>&nbsp;
        <asp:TextBox ID="txtDoc" runat="server"></asp:TextBox>

        <asp:RequiredFieldValidator ControlToValidate="txtDoc" Text="This field is required"
                    ForeColor="Red" runat="server"><img src="Images/icon_error_white.gif" alt="Error" /></asp:RequiredFieldValidator>
                <asp:Button ID="Button1" runat="server" Style="z-index: 1; left: 16px; top: 176px; position: absolute"
                    Text="Create" />
                <br />
                <br />
            </div>
        </asp:View>
        <asp:View ID="View2" runat="server">
            <MSD:User ID="User1" runat="server" />
        </asp:View>
    </asp:MultiView>
</form>

UserForm.aspx.cs

protected void Button1_Click(object sender, EventArgs e)
{
    bool Name= String.IsNullOrWhiteSpace(txtName.Text);
    bool Phone= String.IsNullOrWhiteSpace(txtPhone.Text);
    bool Doc= String.IsNullOrWhiteSpace(txtDoc.Text);


    MultiView1.SetActiveView(View2);
}
public string Name
{
    get { return txtName.Text; }
}
public string Phone
{
    get { return txtPhone.Text; }
}
public string Doc
{
    get { return Doc.Text; }
}

UserControll.ascx

   <div>
        <asp:Label ID="Name" runat="server" Text="Name"></asp:Label>&nbsp;
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>&nbsp;
        <asp:Label ID="Doc" runat="server" Text="Doc"></asp:Label>&nbsp;
        <asp:TextBox ID="txtDoc" runat="server"></asp:TextBox>&nbsp;
        <hr />
    </div>

我需要将view1上的文本传递给view2,女巫是控制器

我是ASP.NET和网络编程的新手,所以任何帮助和评论都很有用 *注意:我没有使用MVC模型

0 个答案:

没有答案