I'm dynamically generating controls on page initialization including controls contained within a TabContainer control. For the DropDownList controls that were added dynamically I need to programmatically add the event handler for the SelectedIndexChanged
event. To do this I wrote a recursive
function to walk through all the controls that were created and if it finds a DropDownList it set's the event handler as follows:
protected void SetDropDownListCallbacks(Control root)
{
foreach(Control c in root.Controls)
{
if (c is DropDownList)
((DropDownList)c).SelectedIndexChanged += new EventHandler(this.DropDownList_SelectedIndexChanged);
else if (c.Controls.Count > 0)
{
SetDropDownListCallbacks(c);
}
}
}
The problem is that when I get to the TabPanel controls the c.Controls.Count is zero. I suspect this is because the controls in the tab panel are actually within a ContentTemplate, but the TabPanel.ContentTemplate property appears to have nothing in it (Text=null)
even though the dynamic controls display/behave normally.
How can I access/search the controls within the TabPanel controls?
I've found that other controls that use the <ContentTemplate> (e.g. Wizard & UpdatePanel) expose a property called
ContentTemplateContainer that is used to access the controls of the ContentTemplate. The TabPanel control does not expose this property. How am I supposed to gain access to the controls in the TabPanel if they're not part of the TabPanel.Controls
collenction and the TabPanel.ContentTemplateContainer is not accessible?
I think you have to work your way through the control collections (forgive me if I'm using the wrong phases). I have a TabContainer which I dynamically add TabPanels to, on each tab I add an UpdatePanel and a PlaceHolder within each UP, in each PH I added
a label.
If I want to change the text of the label I have to do the following (in VB.NET):
Sub AddContent(ByVal strTabID As String)
Dim tabProcesses As TabContainer = Page.FindControl("tabProcesses")
Dim TempTab As TabPanel = tabProcesses.FindControl("tab" & strTabID)
Dim TempUpdatePanel As UpdatePanel = TempTab.FindControl("up" & strTabID)
Dim TempPlaceHolder As PlaceHolder = TempUpdatePanel.FindControl("ph" & strTabID)
Dim TempLabel As Label = TempPlaceHolder.FindControl("lbl" & strTabID)
TempLabel.Text = strTabID
TempUpdatePanel.Update()
End Sub
As you can see I am basically finding each control then finding the next within it.
There are probable better ways which I would be keen to see but this works for now,
I think you're right that the Tab controls should expose their template containers (similar to the way AccordionPane does) and also override FindControl so it works nicely with them. It would be great if you filed a CodePlex bug on this.
Thanks,
Ted
This posting is provided "AS IS" with no warranties, and confers no rights.
I think you have to work your way through the control collections (forgive me if I'm using the wrong phases). I have a TabContainer which I dynamically add TabPanels to, on each tab I add an UpdatePanel and a PlaceHolder within each UP, in each PH I added
a label.
If I want to change the text of the label I have to do the following (in VB.NET):
Sub AddContent(ByVal strTabID As String)
Dim tabProcesses As TabContainer = Page.FindControl("tabProcesses")
Dim TempTab As TabPanel = tabProcesses.FindControl("tab" & strTabID)
Dim TempUpdatePanel As UpdatePanel = TempTab.FindControl("up" & strTabID)
Dim TempPlaceHolder As PlaceHolder = TempUpdatePanel.FindControl("ph" & strTabID)
Dim TempLabel As Label = TempPlaceHolder.FindControl("lbl" & strTabID)
TempLabel.Text = strTabID
TempUpdatePanel.Update()
End Sub
As you can see I am basically finding each control then finding the next within it.
There are probable better ways which I would be keen to see but this works for now,
Daniel
I'm looking for the same thing. So far I've found nothing. Is there something faster or easier to implement then the above workaround?
I've used these post for a LONG time in solving my small issues and I think I finally have somthing that I can contribute.
I have a TabContainer. Within the TabContainer I have a TabPanel. Within the TabPanel I have a FormView. And finally within the FormView I have a Hyperlink that I need to change the NavigateURL on. This solution was very simple and worked for me:
Dim HLink As HyperLink = TabContainer1.FindControl("TabPanel1").FindControl("FormView1").FindControl("HyperLink1")
HLink.NavigateUrl = "
http://www.NewUrl.com "
zabolots
Member
16 Points
25 Posts
How to find controls inside a TabPanel's ContentTemplate?
Feb 22, 2007 12:30 PM|LINK
I'm dynamically generating controls on page initialization including controls contained within a TabContainer control. For the DropDownList controls that were added dynamically I need to programmatically add the event handler for the SelectedIndexChanged event. To do this I wrote a recursive
function to walk through all the controls that were created and if it finds a DropDownList it set's the event handler as follows:
protected void SetDropDownListCallbacks(Control root) { foreach(Control c in root.Controls) { if (c is DropDownList) ((DropDownList)c).SelectedIndexChanged += new EventHandler(this.DropDownList_SelectedIndexChanged); else if (c.Controls.Count > 0) { SetDropDownListCallbacks(c); } } }The problem is that when I get to the TabPanel controls the c.Controls.Count is zero. I suspect this is because the controls in the tab panel are actually within a ContentTemplate, but the TabPanel.ContentTemplate property appears to have nothing in it (Text=null) even though the dynamic controls display/behave normally.
How can I access/search the controls within the TabPanel controls?
FindControl ContentTemplate TabPanel TabContainer
zabolots
Member
16 Points
25 Posts
Re: How to find controls inside a TabPanel's ContentTemplate?
Feb 26, 2007 07:35 PM|LINK
zabolots
Member
16 Points
25 Posts
Re: How to find controls inside a TabPanel's ContentTemplate?
Feb 26, 2007 08:14 PM|LINK
I've found that other controls that use the <ContentTemplate> (e.g. Wizard & UpdatePanel) expose a property called ContentTemplateContainer that is used to access the controls of the ContentTemplate. The TabPanel control does not expose this property. How am I supposed to gain access to the controls in the TabPanel if they're not part of the TabPanel.Controls collenction and the TabPanel.ContentTemplateContainer is not accessible?
Can somebody from MSFT please comment on this?
zabolots
Member
16 Points
25 Posts
Re: How to find controls inside a TabPanel's ContentTemplate?
Feb 28, 2007 07:43 PM|LINK
chafen
Member
2 Points
3 Posts
Re: How to find controls inside a TabPanel's ContentTemplate?
Mar 05, 2007 02:58 PM|LINK
I think you have to work your way through the control collections (forgive me if I'm using the wrong phases). I have a TabContainer which I dynamically add TabPanels to, on each tab I add an UpdatePanel and a PlaceHolder within each UP, in each PH I added a label.
If I want to change the text of the label I have to do the following (in VB.NET):
Sub AddContent(ByVal strTabID As String) Dim tabProcesses As TabContainer = Page.FindControl("tabProcesses") Dim TempTab As TabPanel = tabProcesses.FindControl("tab" & strTabID) Dim TempUpdatePanel As UpdatePanel = TempTab.FindControl("up" & strTabID) Dim TempPlaceHolder As PlaceHolder = TempUpdatePanel.FindControl("ph" & strTabID) Dim TempLabel As Label = TempPlaceHolder.FindControl("lbl" & strTabID) TempLabel.Text = strTabID TempUpdatePanel.Update() End SubTed Glaza [M...
Contributor
4198 Points
847 Posts
Microsoft
Re: How to find controls inside a TabPanel's ContentTemplate?
Mar 08, 2007 07:35 PM|LINK
I think you're right that the Tab controls should expose their template containers (similar to the way AccordionPane does) and also override FindControl so it works nicely with them. It would be great if you filed a CodePlex bug on this.
Thanks,
Ted
zabolots
Member
16 Points
25 Posts
Re: How to find controls inside a TabPanel's ContentTemplate?
Mar 09, 2007 11:57 AM|LINK
I did:
http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=8574
but so far nobody has been assigned or even looked at it apparently. Perhaps I filled out the form incorrectly.
mychucky
Contributor
4358 Points
3709 Posts
Re: How to find controls inside a TabPanel's ContentTemplate?
Mar 15, 2007 05:59 PM|LINK
I'm looking for the same thing. So far I've found nothing. Is there something faster or easier to implement then the above workaround?
VDNCoder
Member
3 Points
5 Posts
Re: How to find controls inside a TabPanel's ContentTemplate?
Apr 13, 2007 01:55 PM|LINK
I've used these post for a LONG time in solving my small issues and I think I finally have somthing that I can contribute.
I have a TabContainer. Within the TabContainer I have a TabPanel. Within the TabPanel I have a FormView. And finally within the FormView I have a Hyperlink that I need to change the NavigateURL on. This solution was very simple and worked for me:
mychucky
Contributor
4358 Points
3709 Posts
Re: How to find controls inside a TabPanel's ContentTemplate?
Apr 13, 2007 02:08 PM|LINK