I have a dynamically added usercontrol that dynamically creates a TabStrip and associated PageViews from a database. For SEO purposes what I want this to do is create the PageViews for some of the tabs initially but also have some of the Tabs that will dynamically add thier PageViews on TabClick. Some of these also get additional user controls added to the PageView.
The problem is that the tabs with PageViews work fine until I click one that loads another page OnPostBack. Once the new PageView is dynamacally added OnPostBack I loose all of the ones that were originally created.
I believe I need to use the multipage PageViewCreated event to persist the dynamically created controls inside a RadPageView such as what is shown on this demo http://demos.telerik.com/aspnet-ajax/tabstrip/examples/applicationscenarios/loadondemand/defaultcs.aspx.
My problem is I am adding the content to the initially created PageViews by placing it into a Literal using Controls.Add which works fine initially. The problem is I can't seem to find it using e.PageView.FindControl to persit it in the PageViewCreated event below which always shows "PageView not found" in the code below.
Any help would be greatly appreciated!
Thanks in advance,
Dave
The problem is that the tabs with PageViews work fine until I click one that loads another page OnPostBack. Once the new PageView is dynamacally added OnPostBack I loose all of the ones that were originally created.
I believe I need to use the multipage PageViewCreated event to persist the dynamically created controls inside a RadPageView such as what is shown on this demo http://demos.telerik.com/aspnet-ajax/tabstrip/examples/applicationscenarios/loadondemand/defaultcs.aspx.
My problem is I am adding the content to the initially created PageViews by placing it into a Literal using Controls.Add which works fine initially. The problem is I can't seem to find it using e.PageView.FindControl to persit it in the PageViewCreated event below which always shows "PageView not found" in the code below.
Any help would be greatly appreciated!
Thanks in advance,
Dave
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
LoadPageTabs(intControlID);
if
(Convert.ToInt32(SessionHandler.UserLevel) > 9)
{
RadMenu1.Visible =
true
;
ScriptBlock1.Visible =
true
;
RadTabStrip1.OnClientContextMenu =
"ShowRadMenu"
;
RadTabStrip1.OnClientTabSelected =
"OnClientTabSelected"
;
}
ConfigureRadEditor();
}
}
protected
void
LoadPageTabs(
int
intPageID)
{
PageLogic pl =
new
PageLogic();
DataTable dt = pl.GetPageTabs(0, intPageID, 0);
if
(dt.Rows.Count > 0)
{
if
(!Page.IsPostBack)
{
lblPgTabID.Text = dt.Rows[0][
"PgTabID"
].ToString();
}
foreach
(DataRow dr
in
dt.Rows)
{
try
{
AddTab(Convert.ToInt32(dr[
"PgTabID"
].ToString()), Convert.ToInt32(dr[
"ParentID"
].ToString()), dr[
"TabName"
].ToString(), Convert.ToInt32(dr[
"ShowPv"
].ToString()), dr[
"PvContent"
].ToString(), dr[
"PvControl"
].ToString(), Convert.ToInt32(dr[
"PvControlID"
].ToString()));
}
catch
(Exception)
{
throw
;
}
}
}
else
{
phAddTab.Visible =
true
;
phTabs.Visible =
false
;
}
}
private
void
AddTab(
int
intPgTabID,
int
intParentID,
string
tabName,
int
intShowPv,
string
pvContent,
string
pvControl,
int
pvControlID)
{
RadTab ParentTab =
new
RadTab();
//tab.ID = "tb" + tabName;
ParentTab.Text = tabName;
ParentTab.Value = intPgTabID.ToString();
ParentTab.Attributes.Add(
"TabID"
, intPgTabID.ToString());
RadTabStrip1.Tabs.Add(ParentTab);
if
(intParentID < 0)
{
PageLogic pl =
new
PageLogic();
DataTable dt = pl.GetPageTabs(0, 0, intPgTabID);
if
(dt.Rows.Count > 0)
{
int
rowcnt = 0;
foreach
(DataRow dr
in
dt.Rows)
{
try
{
RadTab ChildTab =
new
RadTab();
ChildTab.Text = dr[
"TabName"
].ToString();
ChildTab.Value = intPgTabID.ToString();
ChildTab.Attributes.Add(
"TabID"
, dr[
"PgTabID"
].ToString());
ParentTab.Tabs.Add(ChildTab);
if
(intShowPv > 0)
{
AddPageView(ChildTab, Convert.ToInt32(dr[
"PgTabID"
].ToString()), dr[
"PvContent"
].ToString(), dr[
"PvControl"
].ToString(), Convert.ToInt32(dr[
"PvControlID"
].ToString()));
}
if
(rowcnt == 0)
{
ChildTab.Selected =
true
;
}
rowcnt++;
}
catch
(Exception)
{
throw
;
}
}
}
}
if
(intParentID < 1)
{
if
(intShowPv > 0)
{
AddPageView(ParentTab, intPgTabID, pvContent, pvControl, pvControlID);
}
}
}
private
void
AddPageView(RadTab tab,
int
intPgTabID,
string
pvContent,
string
pvControl,
int
pvControlID)
{
Literal litPvContent =
new
Literal();
litPvContent.Text = pvContent;
litPvContent.ID =
"litPv"
+ intPgTabID.ToString();
RadPageView pageView =
new
RadPageView();
// pageView.ID = tabName;
pageView.ID =
intPgTabID.ToString();
pageView.Controls.Add(litPvContent);
if
(pvControl.Length > 0)
{
UserControl userControl = (UserControl)
this
.LoadControl(pvControl);
((CustomControl)userControl).ID =
"Cntl"
+ intPgTabID.ToString();
((CustomControl)userControl).intControlID = pvControlID;
((CustomControl)userControl).intPgMode = 2;
pageView.Controls.Add(userControl);
}
RadMultiPage1.PageViews.Add(pageView);
tab.PageViewID = pageView.ID;
}
private
void
AddHiddenPageView(RadTab tab)
{
int
intPgTabID = Convert.ToInt32(tab.Value);
PageLogic pl =
new
PageLogic();
DataTable dt = pl.GetPageTabs(intPgTabID, 0, 0);
if
(dt.Rows.Count > 0)
{
Literal litPvContent =
new
Literal();
litPvContent.Text = dt.Rows[0][
"pvContent"
].ToString();
RadPageView pageView =
new
RadPageView();
// pageView.ID = tabName;
pageView.ID =
"pv"
+ intPgTabID.ToString();
pageView.Controls.Add(litPvContent);
//pageView.Visible = false;
if
(dt.Rows[0][
"pvControl"
].ToString().Length > 0)
{
UserControl userControl = (UserControl)
this
.LoadControl(dt.Rows[0][
"pvControl"
].ToString());
((CustomControl)userControl).ID =
"Cntl"
+ intPgTabID.ToString();
((CustomControl)userControl).intControlID = Convert.ToInt32(dt.Rows[0][
"pvControlID"
].ToString());
((CustomControl)userControl).intPgMode = 2;
pageView.Controls.Add(userControl);
}
RadMultiPage1.PageViews.Add(pageView);
tab.PageViewID = pageView.ID;
}
}
protected
void
RadMultiPage1_PageViewCreated(
object
sender, RadMultiPageEventArgs e)
{
Literal litPvContent =
new
Literal();
litPvContent.ID =
"litPv1"
+ e.PageView.ID.ToString();
Literal litPvContent1 = (Literal)e.PageView.FindControl(
"litPv"
+ e.PageView.ID.ToString());
if
(litPvContent1 !=
null
)
{
litPvContent.Text = litPvContent1.Text;
e.PageView.Controls.Add(litPvContent);
}
else
{
litPvContent.Text =
"PageView Not Found"
;
}
e.PageView.Controls.Add(litPvContent);
//string userControlName = e.PageView.ID + "CS.ascx";
//Control userControl = Page.LoadControl(userControlName);
//userControl.ID = e.PageView.ID + "_userControl";
//e.PageView.Controls.Add(userControl);
}
protected
void
RadTabStrip1_TabClick(
object
sender, RadTabStripEventArgs e)
{
AddHiddenPageView(e.Tab);
e.Tab.PageView.Selected =
true
;
}