Finding a control in the master page from within a control on the "child" page....

I've seen several examples of finding controls, but I'm struggling with this.  I want to turn a panel to visible and set a label's text field from within a control... All the examples that I've seen, including the really good one at MSDN2 shows Master.FindControl.  When I use that, it says Master is not declared.  Is there an easy way to set the panel and the label from within the control? Am I close?


'---------- My Master page...abbreviated...
<%@ Master Language="VB" CodeFile="Secure_Master.master.vb" Inherits="MasterPage" %>
<%@ Register TagPrefix="cc" TagName="menu" src="leftmenu.ascx"%>

<body>
<form id="formMain" runat="server" align="center">
<cc:menu id="menu" runat="server" pageid="tips"/>
<asp:Panel ID="pnlBreadCrumbs" runat="server" Visible="false">
<asp:Label ID="lblBreadCrumbs" runat="server" Text="I'm a bread crumb..."></asp:Label></td>
</asp:Panel>


'---------- My control page...abbreviated...
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="leftmenu.ascx.vb" Inherits="secure_members_leftmenu" %>

'---------- My control page  code behind file - would like to set those values here
    Private Function SetMiscVals() As Boolean
        Dim bResult As Boolean = False
        Try
            If sSectionTitle.Trim <> "" Then
                Dim myRef_lblBreadCrumbs As Label
                myRef_lblBreadCrumbs = CType(FindControl("lblBreadCrumbs"), Label)
                If Not myRef_lblBreadCrumbs Is Nothing Then
                    myRef_lblBreadCrumbs.Text = sBreadCrumb

                    Dim myRef_pnlBreadCrumbs As Panel
                    myRef_pnlBreadCrumbs = CType(FindControl("pnlBreadCrumbs"), Panel)
                    If Not myRef_pnlBreadCrumbs Is Nothing Then
                        myRef_pnlBreadCrumbs.Visible = True
                    End If
                End If
            End If
        Catch ex As Exception

        End Try
        Return bResult
    End Function

0
taemike
2/27/2007 5:57:03 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

1 Replies
1146 Views

Similar Articles

[PageSpeed] 16

The problem is the control is a self contained unit; it knows nothing of the "outside world" including MasterPages.

You could add arguments to your function: SetMiscVals(Panel CrumbPanel, Label CrumbLabel)

Then your function will have access to them.


Steve Wellens

My blog
0
SGWellens
2/27/2007 9:00:59 PM
Reply:

Similar Artilces:

User Control in Master page raises "clicked" event...how to subscribe to this event in "nested" Master page??
I have a custom user control with several LinkButtons that serve as a common menu for all my pages.  Within this user control, I created a delegate and a custom event...and raise a "clicked" event whenever one of the LinkButtons is clicked. I added this user control to a Master page, then subscribed to that "clicked" event in the Page_Load.  The subscribed event handler within this Master page works fine. My problem is...I created a "nested" Master page from the Master page above, and want to subscribe to the original user control...

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

Updating "Parent" Web Page with Value from Pop-up "Child" Web Page
Hi, all. I'm having a problem updating a cell in a table row on my parent web page with the updated value from my child web page. I am using a script to pass the value back to the parent page (script is executed in child web page button exit event handler). If I put the updated value in a textbox on the parent page, it works fine. However, when I attempt to put the updated value in the table row cell I get an error: table row is not an object or the object is null. NOTE: I am doing this without a postback on the parent page. I tried creating all the rows dynamically in the code beh...

Sharepoint help! Error msg : "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe"
hihi, I have set up a testing virtual server on my local machine. I installed win server 2003, wss 2.0, sql server 2000, and visual studio .net 2003. i tried to create a project in C# but when i build it and import the web part (.dwp) into the page, there is this error msg "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe"  I seached most of the sites and they informed that the problem lies in the safe control in web.config i enter the safe control in web.config but i does not know where to put ...

Problem to use TreeView Control in a 'content page' This Error Occur "Only Content controls are allowed directly in a content page that contains Content controls."
hi I am trying to use the TreeView Control inside the content page (Page that has a master page is a content page). On compiling the project I got the following ASP.Net runtime error: "Only Content controls are allowed directly in a content page that contains Content controls."B@b@R J Issue resolved. I was putting script tag in the content page that is not allowed. when remove the script from content page problem is resolved.B@b@R J...

Control within Master page gets "does not exist in the current context"
Please help me on this. I have a user login control defined in my MasterPage.master : <asp:Login ID="UserLogin" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderPadding="4"                        BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em"                        ForeColor="#333333" Height="87px" OnAuthenticate="Use...

"Error on page" when clciking "Jobs" in "Printer Control" with iManager
Hello all, I have the following issue in iManager : when I click on "Jobs" in "Printer Control" tab for a printer object, I have the following error message : "Error on page"/"Done with Error" in the left down corner of my Internet Explorer (v6.0) If I double click on the error message, I have either "Expected ')'" or "Object Expected" in the error description window. What surprise me is the fact that it occurs only on printers from one of our four NDPSM. (This is why I didn't post on the imanager forum) Tho...

Find Control not "Finding the control"
I'm trying to figure out why this code is not displaying the ControlID for the TextBox which is in a Datagrid in a TemplateColumn: void editClicked(object sender, DataGridCommandEventArgs e) { // Simple script to display the ControlID of the TextBox txtln message.Text = Convert.ToString((TextBox)e.Item.FindControl("txtln")); } <asp:TemplateColumn SortExpression="ln" HeaderText="Last name"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem,"ln") %> </ItemTemplate> <...

Error Rendering Control ... using the Title property of Page requires a header control on the page. (e.g. <head runat="server" />
Hi All,I have a custom control that inherits from CompositeControl and implements INamingContainer and IPostBackDataHandler.  The control is an intelligent BreadCrumb generator for use on a MasterPage.  It generates LinkButtons for the crumbs based on Server.Transfer() calls to and from ClientPages.Instead of the control rendering as the value of its Text property on the aspx page (which it did when I first started it), I get the following error ***************** Error Rendering Control - ControlNameAn unhandled exception has occurred.Using the Title property of the Page ...

"Master pages" for user controls
I'm making a website that consists of mostly dynamically loaded user controls. Many of these controls are essentially full pages, but they are implemented as user controls so that they can be displayed in different ways (displayed by themselves, composed with other user controls, displayed as in-page "popups", etc). Is there any way to have this kind of architecture and still be able to somehow have templates for the content within user controls?Thanks for any suggestions. Sorry. Have you set up the website already? or are you asking some solution for such website here. Any c...

Javascript inside "web user control" not run if load "web user control" under ajax UpdatePanel
I have this problem and please if some can help me, I place here a sample code to see, but in my real problem the web user control have a very complicate javascript. I have a web user control that have some javascript inside, let say for example.1 <script type="text/javascript" > 2 function RunMe() 3 { 4 alert("Client id:<%=ClientID%>"); 5 } 6 </script> 7 8 9 <a href="javascript:RunMe()">Run javascript</a> a simple call to a simple javascript, inside the web user control And now I have...

Dynamically adding "Child" User Controls to "Parent" User Control
Hello group..Need some advice/help with some issue...Am having trouble dealing with nested user controls that i will be having. My business need is as follows...Need to display a Page Header , data Grid(for some details) and Page footer...And the grid will display only a set of data. If i have more data, the parent page should have another set of Page Header, data Grid and Page Footer. So, this is how it looks like***************************Page HeaderGridPage Footer--------Page Break---------Page HeaderGridPage Footer--------Page Break---------Page HeaderGridPage Footer--------Page Break---...

"How to implement ajax control in master page ?"
Hi i have created one master page. i have kept one menu control and i have to give link of some pages. i want to call the other page without the postback.  is it possible to do this one ? i implemented the update panel control, but it is not working.i think we canot solve the this problem using update panel control. which control should have to use for this problem ?Chandra Dev  You cannot call another "page" without the browser refreshing. You may want to turn the other "page" into a user control and then call the user control into a placeholder inside ...

"Global" Login control on Master Page
Hi, I have some problems to get the Login control work the way I want in the VS2005 May CTP. I created a MasterPage with the login control on it. The thing is that I don't want to have the Login.aspx but rather more have the Login control shown on every site until the user logs in. Right now I always get an error as the Login control tries to redirect to the Login.aspx although I have DestinationPageUrl set to: ~/test/Default.aspx. I don't want to specify the auth site in the web.config either as the website consists of 3 master pages each in different sub folders and all of them...

Web resources about - Finding a control in the master page from within a control on the "child" page.... - asp.net.web-forms

Resources last updated: 1/15/2016 10:28:55 AM