如何获取前一页面动态添加的控件的值?
有两个页面,test1.aspx和test2.aspx
test1.aspx页面里的textbox1控件用户会输入数字,根据输入的数字生成相应数量的textbox控件,然后在这些生成的textbox里输入数字.
我在test2.aspx需要获取这些textbox里输入的数字相加的值,请问我该如何获取?我比较喜欢用 Server.Transfer方法传值,这这个方法可以吗?怎么用?
test1.aspx 前台代码
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="test1.aspx.cs" Inherits="Pranser.test1" %><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><asp:ScriptManager ID="XML" runat="server"></asp:ScriptManager><asp:UpdatePanel ID="Update1" runat="server"><ContentTemplate><asp:PlaceHolder ID="Place1" runat="server"><asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged" ></asp:TextBox></asp:PlaceHolder></ContentTemplate></asp:UpdatePanel><asp:Button ID="Button1" OnClick="Button1_Click" runat="server" /></asp:Content>
namespace Pranser{ public partial class test1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void TextBox1_TextChanged(object sender, EventArgs e) { for (int i = 0; i < int.Parse(TextBox1.Text); i++) { TextBox tb = new TextBox(); tb.ID = "tb" + i.ToString(); Place1.Controls.Add(tb); } } protected void Button1_Click(object sender, EventArgs e) { Server.Transfer("test2.aspx"); } }}
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="Pranser.test2" %><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><asp:Label ID="Label1" runat="server"></asp:Label></asp:Content>
namespace Pranser{ public partial class test2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }}