Solved

Tab Panels with Nested UserControls

Posted on 2009-05-19
6
740 Views
Last Modified: 2012-05-07
Hello,

I have a website that has a default ASPX which contains a tabcontainer and four tabs. I dynamically load a usercontrol into a placeholder in each tab when that tab is selected.

The code I am using is:

                    Me.phHOME.Controls.Clear()
                    Dim qControl As Control
                    qControl = LoadControl("uControls/uUPDATES.ascx")
                    phHOME.Controls.Add(qControl)
                    ViewState("ACTIVECONTROL") = "uControls/uUPDATES.ascx"
                    Me.labelHEAD.Text = "myDESK: " & "Home"
                Catch ex As Exception
                    Me.labelHEAD.Text = Err.Description
                End Try

My problem is that one of the tabs has a usercontrol with a menu on it, when the menu has a new item selected it should load another usercontrol into a placeholder with in the parent usercontrol with is a child of the tabpanel. I can get the parent control to show but when you select a new menu item it dissappears and no new control shows.

I have seen that somewhere that dynamic controls should be written into the page_init but I can not see how this could be done if the page has rendered already?

Any help would be appreciated.

Thanks,



ASCX Code.
 
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="uADMIN.ascx.vb" Inherits="uCONTROLS_uADMIN" %>
<%@ Register src="../aCONTROLS/aMANUALIMPORT.ascx" tagname="aMANUALIMPORT" tagprefix="uc1" %>
<table>
    <tr>
        <td>
        </td>
        <td>
            <asp:Menu ID="adminmenu" runat="server">
                <Items>
                    <asp:MenuItem Text="Work Load" Value="Work Load">
                        <asp:MenuItem Text="Manual Import" Value="Manual Import"></asp:MenuItem>
                        <asp:MenuItem Text="Priority" Value="Priority"></asp:MenuItem>
                    </asp:MenuItem>
                </Items>
            </asp:Menu>
        </td>
    </tr>
</table>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:PlaceHolder ID="phMAINADMIN" runat="server"></asp:PlaceHolder>
    </ContentTemplate>
</asp:UpdatePanel>
<asp:Label ID="lblERROR" runat="server" ForeColor="#FF3300"></asp:Label>
 
Code behind:
 
artial Class uCONTROLS_uADMIN
    Inherits System.Web.UI.UserControl
    Protected Sub adminmenu_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles adminmenu.MenuItemClick
        Try
            Me.phMAINADMIN.Controls.Clear()
            Dim qControl As Control
            qControl = LoadControl("../aControls/aMANUALIMPORT.ascx")
            phMAINADMIN.Controls.Add(qControl)
            ViewState("ADMINACTIVECONTROL") = "../aControls/aMANUALIMPORT.ascx"
        Catch ex As Exception
            lblERROR.Text = ex.Message
        End Try
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            Try
                Me.phMAINADMIN.Controls.Clear()
                Dim qControl As Control
                qControl = LoadControl(ViewState("ADMINACTIVECONTROL"))
                Me.phMAINADMIN.Controls.Add(qControl)
                'ViewState("ACTIVECONTROL") = "uControls/uUPDATES.ascx"
                'Me.labelHEAD.Text = "myDESK: " & "Home"
            Catch ex As Exception
                'MsgBox(ex.Message)
 
            Finally
                'mainTC.ActiveTabIndex = 0
            End Try
        Else
            Try
                Me.phMAINADMIN.Controls.Clear()
                Dim qControl As Control
                qControl = LoadControl("../aControls/aMANUALIMPORT.ascx")
                phMAINADMIN.Controls.Add(qControl)
                ViewState("ADMINACTIVECONTROL") = "../aControls/aMANUALIMPORT.ascx"
            Catch ex As Exception
                lblERROR.Text = ex.Message
            End Try
        End If
    End Sub
 
 
End Class

Open in new window

0
Comment
Question by:DanielJay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 11

Assisted Solution

by:Kelvin McDaniel
Kelvin McDaniel earned 40 total points
ID: 24423714
The Page Lifecycle is:
01. PreInit
02. Init
03. InitComplete
04. PreLoad
05. Load
06. LoadComplete
07. PreRender
08. SaveStateComplete
09. Render
10. Unload

Much more detail is available here:
http://msdn.microsoft.com/en-us/library/ms178472.aspx

I'm not sure that the controls you're trying to manipulate are available for use in the Page_Init event... give it a try and see what happens. The next one to try would be the PreRender event.
0
 
LVL 1

Author Comment

by:DanielJay
ID: 24424007
Hi - Thanks for your reply. The controls are being added dynamically at stage 9, Render. So I would not be able to place at the init stage.
0
 
LVL 11

Assisted Solution

by:Kelvin McDaniel
Kelvin McDaniel earned 40 total points
ID: 24431553
Oooh, forgot to mention that User Controls also have a lifecycle... that is "independent" of the Page.

The details:
http://msdn.microsoft.com/en-us/library/system.web.ui.usercontrol_events.aspx

If I correctly understand your goal here... it may be that what you're trying to accomplish needs to be done in the proper event of the User Control itself. You'll probably need programmatically reach into the User Control, passing in the path to the Child-Child User Control (which will be shown because of the menu selection)to be shown), and go from there.

Try that and see what happens.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 1

Accepted Solution

by:
DanielJay earned 0 total points
ID: 24433375
Hi - I solved it in the end adding an ID to each control and using the control by DBauer. I will look at your link though when I have some more time.

Thank you for your help.
0
 
LVL 1

Author Comment

by:DanielJay
ID: 24529189
..
0
 
LVL 11

Expert Comment

by:Kelvin McDaniel
ID: 24529250
No objections; you can close it now.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question