Jump to content

Creating Dynamic ASP.NET Server Controls Using XML


kwilliams

Recommended Posts

I'm following a great article titled "Creating Dynamic ASP.NET Server Controls Using XML" at http://www.devarticles.com/c/a/ASP.NET/Cre...ls-Using-XML/2/, but I'm running into strange problems when I attempt to re-produce the pages.Basically, the ASP.NET server controls show up in the code, but they aren't being displayed on the page. The method I'm using involves XML/XSLT transformation on an ASP.NET page, but I've also tried just attaching the XSLT stylesheet to the XML doc to no avail. So I've included the code that I'm using at the bottom of this post. If anyone can help me to figure out what I'm doing wrong, I'd appreciate it. Thanks.XML DOC:

<?xml version="1.0" encoding="UTF-8"?><test>	<survey name="Example Survey">		<question type="text" name="Title" required="yes"/>		<question type="text" name="Industry"/>		<question type="radio" name="Education">		<choice>High school</choice>		<choice>Some college</choice>		<choice>College</choice>		</question>	</survey> </test>

XSLT DOC:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="remove"><xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/><xsl:template match="/">	<div id="content">	<table>		<xsl:for-each select="//question">			<tr>				<td valign="top"><xsl:value-of select="@name" />				<xsl:if test="@required = 'yes'">					<asp:RequiredFieldValidator ErrorMessage="RequiredField" runat="server" ControlToValidate="{@name}" />				</xsl:if>				</td>				<td>				<xsl:if test="@type='text'">					<asp:TextBox id="{@name}" runat="server" />				</xsl:if>				<xsl:if test="@type='radio'">					<asp:RadioButtonList id="{@name}" runat="server">						<xsl:for-each select="choice">							<asp:ListItem Value="{@value}"><xsl:value-of select="@value"/></asp:ListItem>						</xsl:for-each>					</asp:RadioButtonList>				</xsl:if>				</td>			</tr>		</xsl:for-each>	</table>	<asp:button id="submit" runat="server" Text="Submit" />	</div></xsl:template></xsl:stylesheet>

CODE OUTPUT:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head></head><body>	<form name="_ctl1" method="post" action="index.aspx?page=test" id="_ctl1">	<input type="hidden" name="__VIEWSTATE" value="dDw5OTQ1Mjc4NDc7dDw7bDxpPDE+O2k8Mz47PjtsPHQ8O2w8aTwxPjtpPDM+O2k8Nz47aTw5PjtpPDExPjs+O2w8dDxwPGw8aW5uZXJodG1sOz47bDxEb3VnbGFzIENvdW50eSwgS2Fuc2FzIC0gRmVlZGJhY2sgRm9ybSBURVNUOz4+Ozs+O3Q8cDxsPGhyZWY7PjtsPC9uZXdzaXRlL2RvY3MvY3NzL2dlY2tvLmNzczs+Pjs7Pjt0PHA8bDxjb250ZW50Oz47bDxcZTs+Pjs7Pjt0PHA8bDxjb250ZW50Oz47bDxcZTs+Pjs7Pjt0PHA8bDxjb250ZW50Oz47bDxGcmlkYXksIE9jdG9iZXIgMDYsIDIwMDY7Pj47Oz47Pj47dDw7bDxpPDE+Oz47bDx0PHA8cDxsPFRleHQ7PjtsPEZyaWRheSwgT2N0b2JlciAwNiwgMjAwNjs+Pjs+Ozs+Oz4+Oz4+Oz7sPS4LQzwPyQo7LC8Hr0V7L8jzTw==" />			<!--Dynamic page content from XSLT doc-->			<?xml version="1.0" encoding="iso-8859-1"?>			<div id="content" xmlns:asp="remove">			<table>						<tr>									<td valign="top">Title<asp:RequiredFieldValidator ErrorMessage="RequiredField" runat="server" ControlToValidate="Title" /></td>									<td>												<asp:TextBox id="Title" runat="server" />									</td>						</tr>						<tr>									<td valign="top">Industry</td>									<td>												<asp:TextBox id="Industry" runat="server" />									</td>						</tr>						<tr>									<td valign="top">Education</td>									<td>									<asp:RadioButtonList id="Education" runat="server">												<asp:ListItem Value=""></asp:ListItem>												<asp:ListItem Value=""></asp:ListItem>												<asp:ListItem Value=""></asp:ListItem>									</asp:RadioButtonList>									</td>						</tr>			</table>			<asp:button id="submit" runat="server" Text="Submit" />			</div><!-- end content -->	</form></body></html>

DISPLAY OUTPUT (just text shows up):TitleIndustryEducation

Link to comment
Share on other sites

The problem is that you are generating <asp:*> elements for the XSLT output without later parsing this output with ASP.NET. Such elements aren't supposed to be rendered by the browser, but only by the server.In order to solve the problem, you need some sort of command that will take the output and evaluate it as if it's a server side scripting code.

Link to comment
Share on other sites

The problem is that you are generating <asp:*> elements for the XSLT output without later parsing this output with ASP.NET. Such elements aren't supposed to be rendered by the browser, but only by the server.In order to solve the problem, you need some sort of command that will take the output and evaluate it as if it's a server side scripting code.
Ok, thanks for the info. I think that you can tell that I'm a newbie to all of this.I was able to find another publishing of the article that actually does contain the downloadable code at http://www.dnzone.com/ShowDetail.asp?NewsId=151. I use VB.NET, so I'll have to convert all of the C# code, but I think that it will point me in the right direction. Thanks again.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...