Solved

ASP.NET MasterPage How to Access controls within a contentplaceholder

Posted on 2008-06-15
4
1,877 Views
Last Modified: 2013-11-26
I am trying to create property "genMessage" within a masterpage and access the panel control within a contentholder and read/write the text contained within it.  I can access the contentplaceholder,  it shows a control count of 1,  but I do not see how to read/write the text within it (at the moment the text is within a div tag...)


<<<EXCERPT FROM MASTERPAGE>>>>
...
...
...
    <div>
        <asp:contentplaceholder id="MenuContainer" runat="server">
            <a href="~/CustomNavBar.ascx">~/CustomNavBar.ascx</a>
        </asp:contentplaceholder>
        
        <asp:contentplaceholder id="mainContentContainer" runat="server">
        </asp:contentplaceholder>
 
        <asp:contentplaceholder id="generalMessages" runat="server">
        
          <asp:Panel ID="msgContent" runat="server"  BackColor="RosyBrown" ForeColor="Aqua" Width="631px">
            <div>
            This page is still under contruction.  Please check you email for update information or check back soon.
            </div>
          </asp:Panel>
        
        </asp:contentplaceholder>
 
    </div>
...
...
...
 
<<<From The Associated MasterPage vb file>>>
 
    Public Property genMessage() As String
        Get
            Dim cph As ContentPlaceHolder = New ContentPlaceHolder
            cph = Me.FindControl("generalMessages")
            If Not cph Is Nothing Then
                Dim lctrl As LiteralControl = New LiteralControl
                lctrl = CType(cph.Controls.Item(0), LiteralControl)
                Return pnl.ToString
 
            Else
                Return String.Empty
            End If
 
        End Get
 
        Set(ByVal value As String)
            Dim pnl As Panel = New Panel
            pnl = Me.FindControl("msgContent")
            If Not pnl Is Nothing Then
                Page.ClientScript.RegisterClientScriptBlock(GetType(Page), "GENERALMESSAGE", value)
                'Page.RegisterClientScriptBlock("SETGENERALMESSAGE", value)
            End If
        End Set
    End Property

Open in new window

0
Comment
Question by:Howard Bash
[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
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Ajay Sharma earned 250 total points
ID: 21791083
I think line no. 37 should be corrected.

instead of
Return pnl.ToString

it should be
Return lctrl.ToString

==========

Secondly Asp.net Panel control does not have a Text property, so if you want to get set the text use label inside panel
0
 
LVL 13

Assisted Solution

by:sm394
sm394 earned 250 total points
ID: 21791748
you can access controls in contentplaceholder  by using  controls client ID property
<%= btnSearch.ClientID %> In your case  msgContent.ClientID
also this is good article about Master pages and content pages

http://www.odetocode.com/articles/450.aspx
read section "FindControl, JavaScript, and Naming Containers" for more info
0
 
LVL 13

Expert Comment

by:sm394
ID: 21791802
0
 
LVL 1

Author Closing Comment

by:Howard Bash
ID: 31467453
I appreciate the pointers.  I only wish that one of my experts had included some trival complete example.  But,  definitely headed me in the right direction.
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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