Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 15th, 2008, 01:41 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Master Page Method: Code-Behind for Content Page

I'm using the Master Page method on my site, but I'm having a problem with using the content page's code-behind doc (VB). If I place a block of code in the Master Page's code-behind file, it works great. But if I place that same block of code in the content page's code-behind page, it doesn't work.

I thought that I had everything set up properly, but obviously the content's CB is not being called properly from the content page. Below is my code. Please let me know what I'm doing wrong. Thanks.

Master Code-Behind Page(MasterPage.master.vb)
Code:
Partial Class MasterPage
    Inherits System.Web.UI.MasterPage
    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        'Assign path to FileInfo Class
        Dim strXMLPath_mc As String, strXSLPath_mc As String
        strXMLPath_mc = "docs/xml/content.xml" 'xml doc
            strXSLPath_mc = "docs/xslt/content.xsl" 'xsl doc

        'Assign maincolumn XML/XSLT transformation properties
        xslTransform_mc.DocumentSource = strXMLPath_mc
        xslTransform_mc.TransformSource = strXSLPath_mc
    End Sub
End Class
Master Page (MasterPage.master)
Code:
<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" Explicit="True" Debug="True" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
</head>
<body>
    <div id="content">
        <asp:Xml id="xslTransform_mc" runat="server"></asp:Xml>
    </div>
</body>
</html>
Content Page (content.aspx)
Code:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" CodeFile="content.aspx.vb" Inherits="content" AutoEventWireup="false" title="Content Page" %>
Content Code-Behind Page (content.aspx.vb)
Code:
Partial Class content
    Inherits System.Web.UI.Page

    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not Page.IsPostBack Then
            'Create the XsltArgumentList object
            Dim args As New XsltArgumentList()

            'Declare form variables
            Dim category_form As String = Request.Form("txtCategory")
            Dim fullname_form As String = Request.Form("txtFullName")

            'Declare XsltArguments
            If category_form <> "" Then
                args.AddParam("xslt_category", "", category_form)
            End If
            If fullname_form <> "" Then
                args.AddParam("xslt_fullname", "", fullname_form)
            End If
        End If
    End Sub
End Class
XML doc (content.xml)
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<content>
    <field id="category">
        <name>txtCategory</name>
        <title>Category</title>
        <type>text</type>
        <maxlength>40</maxlength>
        <size>20</size>
        <required>false</required>
    </field>

    <field id="fullname">
        <name>txtFullName</name>
        <title>Full Name</title>
        <type>text</type>
        <maxlength>40</maxlength>
        <size>20</size>
        <required>false</required>
    </field>
</content>
XSLT doc (content.xsl)
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:variable name="currentpath">http://www.mysite.com/content.aspx</xsl:variable>
<xsl:param name="xslt_category" select="''" />
<xsl:param name="xslt_fullname" select="''" />
    <xsl:template match="/">

        <form name="formFeedback" action="{$currentpath}" method="post">
            <xsl:for-each select="content/field">
                <input id="{@id}" name="{name}" title="{title}" type="{type}" maxlength="{maxlength}" size="{size}" value="" /><br />
            </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
KWilliams
 
Old May 16th, 2008, 12:34 AM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You mean if you move that Page_Load method from master page to content page it doesn't work? How does it not work? It doesn't compile? What is the error?
 
Old May 28th, 2008, 04:40 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:You mean if you move that Page_Load method from master page to content page it doesn't work? How does it not work? It doesn't compile? What is the error?
No, that's not what I meant. Sorry about the confusion. I have some code that works fine in the Master Page's Page_Load method, but doesn't work in the Content Page's Page_Load method. I did receive part of a solution from someone else by changing AutoEventWireup="false" to AutoEventWireup="true". That change made some of the basic example code on the code-behind page work fine, like this:

content.aspx.vb
Code:
Partial Class content
    Inherits System.Web.UI.Page

    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)    
            Dim strHelloWorld As String = "Hello World!"
            Response.Write("Message: " & strHelloWorld & "<br />") 'TEST
End Class
RESULT:
Message: Hello World!

...but when I try to do add more complex code (see in original post) involving changing XSLT parameters, it doesn't work. But that same code *does* work fine when placed in the Master Page's Page_Load method. So the issue is obviously not due to the code, but the order in which the code is processed by the server.

And since the content page and it's code-behind is supposed to be loaded first when using the Master Page method, I'm confused on what the problem is. Please let me know if you have any other questions, and thanks for your help.

KWilliams
 
Old June 2nd, 2008, 12:57 PM
Authorized User
 
Join Date: Nov 2006
Location: Valparaiso, IN, USA.
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default

Actually, the order of events is a little more complicated than what you mentioned here. It goes more like:

* - Master Page child controls Initialization.
* - Content Page child controls Initialization.
* - Master Page Initialization.
* - Content Page Initialization.
* - Content Page Load.
* - Master Page Load.
* - Master Page child controls Load.
* - Content Page child controls Load.

But that may not be your problem. I am a little confused about the code you posted.
It looks like you are trying to pass some arguments from the child page to the master page. You might want to
consider creating a public argument list variable in the master page and then append your arguments from the
child page to the list in the master page.

The child page will have to have the MasterType statement at the top i.e.:
<%@ MasterType VirtualPath="~/pages/MasterPage.master" %>

And then be sure to append the arguments in an event on the child page that occurs
before you need the arguments in the master page.

Good luck.


What you don't know can hurt you!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Master Page and Content Page with Java script Harjinder ASP.NET 2.0 Professional 1 February 1st, 2008 10:31 AM
Master Page refresh only the content skyler ASP.NET 2.0 Professional 5 May 2nd, 2007 06:52 AM
master page and content page interaction mrjoka ASP.NET 2.0 Basics 0 March 15th, 2007 10:45 AM
Access Master page control from Content page. angshujit ASP.NET 2.0 Basics 3 January 11th, 2007 06:20 AM
content page viewstate value in Master Page cbe_seenu ASP.NET 2.0 Professional 0 August 1st, 2006 01:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.