p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 (http://p2p.wrox.com/forumdisplay.php?f=229)
-   -   Listing 8-10 and Listing 8-16. (http://p2p.wrox.com/showthread.php?t=49403)

Asp.Net October 25th, 2006 12:08 AM

Listing 8-10 and Listing 8-16.
 
A MusterPage that exposes a custom property.
Listing 8-10. Page_266 Chapter_8 Professional ASP.NET 2.0

Hello There!
I discovered a little problem in the code.
By having the brackets you will receive a following {error}:
'ASP.masterpage_masterpage_master.PageHeadingTitle ' is a 'property' but is used like a 'method'
Fix: Remove the brackets.

Take a look at the <html> code of the MasterPage:
//----------------------------------------------------------

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>My Company MasterPage</title>
</head>
<body>
    <form id="form1" runat="server">
     <table cellpadding ="3" border ="1">
        <tr bgcolor ="silver">
         <td colspan ="2">
         <h1><% = PageHeadingTitle() %></h1>
         <b>User's GUID:&nbsp;&nbsp;
         <asp:Label ID ="Label1" runat ="server"></asp:Label></b>
         </td>
        </tr>
            <tr>
             <td>
             <asp:ContentPlaceHolder ID ="ContentPlaceHolder1" runat ="server">
             </asp:ContentPlaceHolder>
             </td>
                 <td>
                     <asp:ContentPlaceHolder ID ="ContentPlaceHolder2" runat ="server">
                     </asp:ContentPlaceHolder>
                 </td>
                 </tr>
                    <tr>
                        <td colspan ="2">
                            Copyright 2006 - My Company
                        </td>
                    </tr>
            </table>
        </form>
</body>
</html>

//-----------------------------------------------------------------


Using Page_Preinit to assign the master page programmaticallly
This is Listing 8-16. Page 272.

Concerns toVB and C#

This one is tricky :)

//------------------------------------------------------
<%@ Page Language="C#" %>


<script runat="server">
                    // Do not write PreInit Use small (i)
    protected void Page_Preinit(object sender, System.EventArgs e)
    {
        Page.MasterPageFile = "~/masterPage/MasterPage2.master";
    }

</script>

//----------------------------------------------------------
Bye :)

joeller February 6th, 2008 01:11 PM

Listing 8-10 and 8-11 purport to show how a public property set on the master page using inline server-side code is accesible from the content page. However when I implement this code in my masterpage and content page like so;

 Dim m_sPageHeadingTitle As String = "HIFLD Web Site"
        Public Property PageHeadingTitle() As String
            Get
                Return m_sPageHeadingTitle
            End Get
            Set(ByVal value As String)
                m_sPageHeadingTitle = value
            End Set
        End Property

an on the content page;

<%@ Page Language="VB" MasterPageFile="~/HIFLDMaster.master" Title="HSIP Gold Request Form" %>
<%@ MasterType VirtualPath="~/HIFLDMaster.master" %>

<script runat="server" language="vb">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

        Me.Master.PageHeadingTitle = "HSIP Gold Request Form"
    End Sub

</script>


I get an error on the content page stating 'PageHeadingTitle' is not a member of 'System.Web.UI.MasterPage'. Were there changes made to ASP.Net 2.0 Master pages after the book was written that keeps this code from working?


All times are GMT -4. The time now is 01:55 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.