I'm using the Accordion control but i have some troubles while combine it with my custom UserControl.
When i'm tring to add my UserControl to the Content property of the AccordionPane, it's not working.
Also, it's doesnt throw any exception. It's just not look like doin what im ask for.
My custom UserControl (named: "MailAddress.ascx") is pretty empty of value. it's just contain "<p>blabla</p>". I'm sure that it's working (added it manually to my webpage and it's working.
The next code is creating the AccordionPane dynamicly:
Accordion1.Controls.Add(pane1);
The first question is that possible to use custom UserControl as a content of AccordionPane?
I have a FAQ page I create dynamically. There are 2 loops, first one gets a group name and creates a new Accordion control. The second one, inside the first one, gets all the items in the group and displays them as AccordianPanes.
Dim group = From g In db.FaqGroups _
Order By g.Name _
Select g
For Each gr In group
Dim gId As Integer = gr.ID
Dim ac As New Accordion
Dim litDivS As New LiteralControl
litDivS.Text = "<br /><div class=faqHeaderDiv>"
Dim litDivE As New LiteralControl
litDivE.Text = "</div>"
Dim litGroup As New LiteralControl
litGroup.Text = gr.Name
ac.ID = "accord" + gr.ID.ToString()
ac.HeaderCssClass = "accordionFaqHeader"
ac.ContentCssClass = "accordionFaqContent"
ac.TransitionDuration = 250
ac.FadeTransitions = True
ac.RequireOpenedPane = False
ac.SelectedIndex = -1
Dim quest = From q In db.Faqs _
Order By q.Question _
Where q.GroupID = gId _
Select q
For Each qu In quest
Dim ap As New AccordionPane
ap.EnableViewState = True
ap.ID = qu.ID
Dim litHeader As New LiteralControl
litHeader.ID = "lblHeader" + qu.ID.ToString()
litHeader.Text = qu.Question
ap.HeaderContainer.Controls.Add(litHeader)
Dim litContent As New LiteralControl
litContent.ID = "lblContent" + qu.ID.ToString()
litContent.Text = qu.Answer + "<br /><br />"
ap.ContentContainer.Controls.Add(litContent)
ac.Panes.Add(ap)
Next
PlaceHolder1.Controls.Add(litDivS)
PlaceHolder1.Controls.Add(litGroup)
PlaceHolder1.Controls.Add(litDivE)
PlaceHolder1.Controls.Add(ac)
Next
Great, glad to help. For further clarification, what you did when you created a New instance of MailAddress was just gave your current page access to the MailAddress class not the user interface (ascx). Using the LoadControl() method will give you the
user interface on the page similar to how you register it on your aspx page:
Member
1 Points
3 Posts
AccordionPane And UserControl
Jan 12, 2010 06:56 AM|YehonatanB|LINK
hey guys,
I'm using the Accordion control but i have some troubles while combine it with my custom UserControl.
When i'm tring to add my UserControl to the Content property of the AccordionPane, it's not working.
Also, it's doesnt throw any exception. It's just not look like doin what im ask for.
My custom UserControl (named: "MailAddress.ascx") is pretty empty of value. it's just contain "<p>blabla</p>". I'm sure that it's working (added it manually to my webpage and it's working.
The next code is creating the AccordionPane dynamicly:
The first question is that possible to use custom UserControl as a content of AccordionPane?
What could be that problem?
Thanks Alot!
Star
9197 Points
2576 Posts
Re: AccordionPane And UserControl
Jan 12, 2010 08:24 AM|b471code3|LINK
I have a FAQ page I create dynamically. There are 2 loops, first one gets a group name and creates a new Accordion control. The second one, inside the first one, gets all the items in the group and displays them as AccordianPanes.
Member
1 Points
3 Posts
Re: AccordionPane And UserControl
Jan 12, 2010 09:06 AM|YehonatanB|LINK
When i'm using the LiteralControl, there are no problem.
But when i'm tring to use more flexable solution (In my case "User Control") - it's not working.
Is that possible to use an UserControl as the content of AccordionPane?
Thanks.
Star
9197 Points
2576 Posts
Re: AccordionPane And UserControl
Jan 12, 2010 10:11 AM|b471code3|LINK
Have you tried using the LoadControl() method?
Control uc = LoadControl("~/Location/OfYour/UserControl.ascx")
Then add uc to the controls collection in the content container of the accordian pane.
Member
1 Points
3 Posts
Re: AccordionPane And UserControl
Jan 12, 2010 11:08 AM|YehonatanB|LINK
Bravo!
That's solve the problem.
Thank you!
Star
9197 Points
2576 Posts
Re: AccordionPane And UserControl
Jan 12, 2010 01:13 PM|b471code3|LINK
Great, glad to help. For further clarification, what you did when you created a New instance of MailAddress was just gave your current page access to the MailAddress class not the user interface (ascx). Using the LoadControl() method will give you the user interface on the page similar to how you register it on your aspx page: