Custom webcontrol

V

Veerle

Hi,

I use the infragistics tabcontrol on several pages of my application,
that looks like this:

<igtab:UltraWebTab ID="MyTabPage" runat="server">
<Tabs>
<igtab:Tab Key="Tab1" Text="Title for tab 1">
<ContentTemplate>
Content of tab 1, can contain usercontrols or
webcontrols
</ContentTemplate>
</igtab:Tab>
<igtab:Tab Key="Tab2" Text="Title for tab 2">
<ContentTemplate>
Content of tab 2, can contain usercontrols or
webcontrols
</ContentTemplate>
</igtab:Tab>
</Tabs>
</igtab:UltraWebTab>
</ao:panel>

I tried creating my own tabcontrol, internally using the infragistics
tabcontrol to do it. The markup now looks like:

<ao:TabView runat="server" ID="MyTabPage">
<ao:Tab runat="server" ID="Tab1" Title="Title for tab 1">
Content of tab 1, can contain usercontrols or webcontrols
</ao:Tab>
<ao:Tab runat="server" ID="Tab2" Title="Title for tab 2">
Content of tab 2, can contain usercontrols or webcontrols
</ao:Tab>
</ao:TabView>

On the first tab, there are some controls in the markup that are set
to Invisible = true in the code behind of the page (on prerender).
Also, the second tab is set to Invisible = false in the code behind of
the page (on prerender).

There is also a button on the page, and when clicked, the second tab
is changed to Visible = true, in other words: there is a postback that
changes the second tab from invisible to visible.
For the infragistics tabcontrol, this is done by:
MyTabPage.Tabs[1].Visible = false;
For my custom tabcontrol, this is done with the same syntax:
MyTabPage.Tabs[1].Visible = false;

Now the problem: when using the infragistics tabcontrol and switching
the second tab from invisible to visible, the invisible controls on
the first tab stay invisible. In my custom tabcontrol, the invisible
controls on the first tab become visible as well, and of course I
don't want that. I'm probably making a beginners mistake (because I am
a beginner), but I have no clue what the source of the problem is...

Here is my code:

[DefaultProperty("Tabs"),
ParseChildren(true, "Tabs")]
public class TabView : CompositeControl, INamingContainer
{
private List<Tab> _tabs;
private UltraWebTab _ultraWebTab;

protected override void CreateChildControls()
{
Controls.Clear();

_ultraWebTab = new UltraWebTab();
foreach(Tab tab in Tabs)
{
Infragistics.WebUI.UltraWebTab.Tab tabItem = new
Infragistics.WebUI.UltraWebTab.Tab(tab.Title);
tabItem.Key = tab.ID;
tabItem.ContentPane.Controls.Add(tab);
_ultraWebTab.Tabs.Add(tabItem);
}
this.Controls.Add(_ultraWebTab);
ChildControlsCreated = true;

ClearChildViewState();
}


[DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public List<Tab> Tabs
{
get
{
if (_tabs == null)
_tabs = new List<Tab>();
return _tabs;
}
}

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
EnsureChildControls();
foreach (Infragistics.WebUI.UltraWebTab.Tab tabItem in
_ultraWebTab.Tabs)
{
if (tabItem.ContentPane.Controls.Count == 1)
{
Tab tab = tabItem.ContentPane.Controls[0] as Tab;
if (tab != null)
tabItem.Visible = tab.Visible;
}
}
}
}

public class Tab : Panel, INamingContainer
{
public string Title
{
get
{
return (string)ViewState["TabTitle"] ?? "";
}
set
{
ViewState["TabTitle"] = value;
}
}

public override bool Visible
{
get
{
return (bool?)ViewState["VisibleTab"] ?? true;
}
set
{
ViewState["VisibleTab"] = value;
}
}
}
 
V

Veerle

On the first tab, there are some controls in the markup that are set
to Invisible = true in the code behind of the page (on prerender).
Also, the second tab is set to Invisible = false in the code behind of
the page (on prerender).

I forgot to mention something important:
I only set the controls on the first tab to Invisible = true in the
prerender when it's not a postback. When I also set it when it is a
postback, then the problem is solved. But when using the Infragistics
control, it does work when only setting the Invisible when it's not a
postback, so I would really like to get that to work in my custom
tabcontrol as well!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top