2012-07-09 71 views
0

我有一些动态的表格,包含一些文本框(也是动态的)和一些按钮,它们可以回发onclick。 点击按钮后,我怎样才能使页面记住回发后在框中输入的文字?asp.net在回发中保存控制值

+0

你能证明你试过吗?或者至少有一些代码?它很难帮助这样! – Thousand 2012-07-09 06:54:52

回答

1

你必须创建一个tymer控制单击event.For是创建一个新的用户控件。添加公共属性以添加您必须添加的控件。在Web用户控制页面INIT和Page_load事件中添加所需数量的控件。希望这会起作用。

//IN web user control aspx page add a place holder in which u add your dynamic controls 
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> 


    <asp:PlaceHolder runat="server" ID="mycontrol"/> 

    // WEb User Control Code Behind 

    // Create public properties 

    public int totalnoOfcontrols 
    { 
    get; 
    set; 
    } 

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (IsPostBack) 
    { 
     // save values here 
    } 
} 
protected void Page_Init(object sender, EventArgs e) 
{ 
    // create dynamic controls here 
    TextBox t = new TextBox(); 
    t.Text = ""; 
    t.ID = "myTxt"; 
    mycontrol.Controls.Add(t); 
} 
+0

不知道如何,因为所有的工作都在Timer_Tick方法做这工作。 – user1468537 2012-07-09 07:45:04

+0

U表示控件在tymer Tick事件产生的? – 2012-07-09 08:04:16

+0

是因为创建控制量是基于一些计算和计时器那里的的UpdateProgress工作 – user1468537 2012-07-09 08:07:20

0

您必须使用Page_Init/Load事件处理程序来创建控件运行时(动态)。

0

对于您可以使用ViewState的

string data = ViewState["myData"]; 

ViewState["myData"] = data;