日期:2014-05-16  浏览次数:20434 次

点击按钮新增一个TextBox,为什么关闭浏览器重新打开刚新增的TextBox还在?

//前台显示代码
<body>
    <form id="form1" runat="server">
    <div runat="server">
        <asp:Panel ID="Panel1" runat="server">

        </asp:Panel>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" 
             />
    </div>
    </form>
</body>

//后台代码
public partial class Default4 : System.Web.UI.Page
{
    static int i = 1;
    static List<Panel> palList = new List<Panel>();

    protected void Page_Load(object sender, EventArgs e)
    {
        RestoreTextBox();  
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Panel a = new Panel();
        a.ID = "div" + i;
         TextBox tx1 = new TextBox();  
         tx1.ID = "txta" + i;
         tx1.Text = "txta" + i;
         a.Controls.Add(tx1);

         TextBox tx2 = new TextBox();
         tx2.ID = "txtb" + i;
         tx2.Text = "txtb" + i;
         a.Controls.Add(tx2);

         palList.Add(a);
         Panel1.Controls.Add(a);

           i++;  
       

    }
    public void RestoreTextBox()  {  
            foreach (Panel tx in palList)  {  
                if (tx != null)  {
                    Panel1.Controls.Add(tx);
                }  
            }
       }  

}



想问的是为什么关闭浏览器重新打开刚新增的TextBox还在?应该是恢复到默认的才对呀
------解决方案--------------------
if (IsPostBack) RestoreTextBox();
------解决方案--------------------
为啥不用jq。。。。
------解决方案--------------------
pro