i am adding 2 controls dynamically, a textbox, and a button. they add ok, to each of the 3 tabs, i add them to a pageview.
the problem is that when i click the button in any tab, is causing a postback, and then the controls disapear.
how can i do to persist the controls after the postback is made?
i am using version 2008.1.415.20
the problem is that when i click the button in any tab, is causing a postback, and then the controls disapear.
how can i do to persist the controls after the postback is made?
i am using version 2008.1.415.20
1 Answer, 1 is accepted
0
Kevin Babcock
Top achievements
Rank 1
answered on 10 Jul 2008, 03:23 AM
Hello Esteban,
You can use the ViewState collection of the page to store any configurations you might need to recreate the controls and add them to the page during a postback. This will allow you to persist your dynamic controls across postbacks.
Please let me know if you continue to need help.
Sincerely,
Kevin Babcock
You can use the ViewState collection of the page to store any configurations you might need to recreate the controls and add them to the page during a postback. This will allow you to persist your dynamic controls across postbacks.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TabStrip.aspx.cs" Inherits="TabStrip" %> | |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<title>Untitled Page</title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> | |
<telerik:RadTabStrip ID="RadTabStrip1" runat="server" | |
MultiPageID="RadMultiPage1"> | |
<Tabs> | |
<telerik:RadTab Text="One" /> | |
<telerik:RadTab Text="Two" /> | |
</Tabs> | |
</telerik:RadTabStrip> | |
<telerik:RadMultiPage ID="RadMultiPage1" runat="server"> | |
<telerik:RadPageView ID="RadPageView1" runat="server" | |
OnLoad="RadPageView1_Load" > | |
<asp:Button ID="Button1" runat="server" | |
Text="Add TextBox" | |
OnClick="Button1_Click" /> | |
</telerik:RadPageView> | |
<telerik:RadPageView ID="RadPageView2" runat="server" | |
OnLoad="RadPageView2_Load" > | |
<asp:Button ID="Button2" runat="server" | |
Text="Add Button" | |
OnClick="Button2_Click" /> | |
</telerik:RadPageView> | |
</telerik:RadMultiPage> | |
</form> | |
</body> | |
</html> | |
using System; | |
using System.Web.UI.WebControls; | |
public partial class TabStrip : System.Web.UI.Page | |
{ | |
protected void RadPageView1_Load(object sender, EventArgs e) | |
{ | |
if (ViewState["RadPageView1_Button_Text"] != null) | |
{ | |
var button = new Button(); | |
button.Text = ViewState["RadPageView1_Button_Text"] as string; | |
button.Click += new EventHandler(Button_Click); | |
RadPageView1.Controls.Add(button); | |
} | |
} | |
protected void RadPageView2_Load(object sender, EventArgs e) | |
{ | |
if (ViewState["RadPageView2_TextBox_Text"] != null) | |
{ | |
var textbox = new TextBox(); | |
textbox.Text = ViewState["RadPageView2_TextBox_Text"] as string; | |
RadPageView2.Controls.Add(textbox); | |
} | |
} | |
protected void Button1_Click(object sender, EventArgs e) | |
{ | |
var button = new Button { Text = "Click me!" }; | |
button.Click += new EventHandler(Button_Click); | |
RadPageView1.Controls.Add(button); | |
ViewState["RadPageView1_Button_Text"] = button.Text; | |
} | |
protected void Button2_Click(object sender, EventArgs e) | |
{ | |
var textbox = new TextBox { Text = "Write in me!" }; | |
RadPageView2.Controls.Add(textbox); | |
ViewState["RadPageView2_TextBox_Text"] = textbox.Text; | |
} | |
protected void Button_Click(object sender, EventArgs e) | |
{ | |
// Do something | |
} | |
} | |
Please let me know if you continue to need help.
Sincerely,
Kevin Babcock