kwilliams
05-15-2008, 02:42 PM
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)
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)
<%@ 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><!-- end content -->
</body>
</html>
Content Page (content.aspx)
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" CodeFile="content.aspx.vb" Inherits="content" AutoEventWireup="false" title="Content Page" %>
Content Code-Behind Page (content.aspx.vb)
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)
<?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)
<?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>
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)
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)
<%@ 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><!-- end content -->
</body>
</html>
Content Page (content.aspx)
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" CodeFile="content.aspx.vb" Inherits="content" AutoEventWireup="false" title="Content Page" %>
Content Code-Behind Page (content.aspx.vb)
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)
<?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)
<?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>