Welcome to WebmasterWorld Guest from 34.236.145.124

Forum Moderators: ocean10000

Message Too Old, No Replies

ascx panel access issue

     
8:49 pm on Aug 6, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


I have a website I am designing it is layed out with a Masterpage, a few ascx pages and a default page (for now). What I need to do is access a content panel that is in the default page. However, I cannot seem to get the control. Here is the code I am using.

Protected Sub searchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myControl As New Control
myControl = Page.FindControl("bodyContent")

'find my control
Dim searchControl As UserControl = CType(LoadControl("Search.ascx"), UserControl)

myControl.Controls.Add(searchControl)

End Sub

To give you the layout. The master page registers the ascx page and puts it in a content pane on the left. Then, the default page is a child of the master page and loads the initial content into the main frame on the right. The left conent has three panes. If you open the search pane and click on the search button. It gives you a null reference error because I am not getting the panel correctly. Since the search button is in the ascx page that is loaded by the master page, I'm not for sure how to do this. Here is where the panel is in my default page. Thanks,

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:Panel ID="bodyContent" runat="server">
</asp:Panel>
</asp:Content>

2:55 pm on Aug 8, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


try this instead

myControl = Page.Master.FindControl("bodyContent")

1:55 pm on Aug 10, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


Thanks