日期:2014-05-17  浏览次数:20505 次

在局部刷新时,动态创建多个TextBox后,如何保存TextBox的Text属性的值?
大家好,请教一个问题:
     在局部刷新时,动态创建多个TextBox后,如何保存TextBox的Text属性的值?

------解决方案--------------------
给你写了一个例子:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestAddText.aspx.cs" Inherits="TestAddText" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="插入Txt" />
        &nbsp;
        <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="选择最大" />
        &nbsp;
        <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="删除最大" />
        <hr />
        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        <hr />
        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="回发测试" />
    </form>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web.UI.WebControls;

public partial class TestAddText : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.PlaceHolder1.Controls.Clear();
        foreach (var id in IDs)
        {
            var txt = new TextBox { ID = id };
            this.PlaceHolder1.Controls.Add(txt);
            txt.TextChanged += txt_TextChanged;
        }
 &nb

相关资料更多>