2012-07-09 69 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;