Reputation: 703
I have a dynamic table with some textboxes (also dynamic) and some buttons which do postback onclick. How can I make the page remember what text was entered in the boxes after postback, after clicking a button?
Upvotes: 0
Views: 3400
Reputation: 6123
You have to create controls in a tymer click event.For that Create a new user control. Add public Properties in it for adding how much controls u have to add. And in Web user control Page INit and Page_load event Add the required number of controls. Hope this will work.
//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);
}
Upvotes: 1
Reputation: 4327
For that you can use the ViewState
string data = ViewState["myData"];
ViewState["myData"] = data;
Upvotes: 0
Reputation: 94635
You have to use Page_Init/Load
event handler to create controls runtime (dynamically).
Upvotes: 0