Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with transform XSL that incude asp.net controls and validation controls!!!!

4 views
Skip to first unread message

Forum

unread,
Jul 9, 2003, 9:11:32 AM7/9/03
to
Please help me.
I have problem with transform xml
Protected WithEvents GeneralXMLWeb As System.Web.UI.WebControls.Xml
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim xmldoc As New XmlDocument()

xmldoc=result of Function() *

GeneralXMLWeb.Document = xmldoc

Dim treeView As XslTransform = New XslTransform()

treeView.Load(Server.MapPath("file.xslt"))

GeneralXMLWeb.Transform = treeView

----------------------------------------------------------------------------
----------------------------------------

("file.xslt") file include some asp.net controls:

<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" />

......

<asp:comparevalidator id="{@ID}" Runat="server" Display="{@DISPLAY}"
ValueToCompare="{@VALUE_TO_COMPARE}"
ControlToValidate="{@CONTROL_TO_VALIDATE}"
ControlToCompare="{@CONTROL_TO_COMPARE}" type="{@TYPE}"
operator="{@OPERATOR}"
ErrorMessage="{@ERROR_MESSAGE}"></asp:comparevalidator>

.....

<asp:TextBox id="C_{@ID}" runat="server" readonly="{@READ_ONLY}"
ENABLED="{@ENABLED}" title="{@TITLE}"
onchange="ClientOnChange();SetTextBoxValue({@ID}, this);" size="{@SIZE}"
style="Z-INDEX: 101; LEFT: {@LEFT}px; POSITION: {@POSITION};
TOP:{@TOP}px;visibility:{@VISIBLE};text-decoration:{@TEXT-DECORATION};font-w
eight:{@FONT-WEIGHT};font-style:{@FONT-STYLE}"><xsl:value-of
select="./text()"/></asp:TextBox>

----------------------------------------------------------------------------
----------------------------------------------------------

But after load page "Page_validators " collection is empty ("undefined") and

not one of the validation is not work.

I tried to solver this problem :

Protected WithEvents MyTree As System.Web.UI.WebControls.Label

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

treeDoc = New XPathDocument(Server.MapPath("file.xml")) ***

Dim treeView As XslTransform = New XslTransform()

Dim sw As New StringWriter()

treeView.Load(Server.MapPath("file.xslt"))

treeView.Transform(treeDoc, Nothing, sw)

Dim result As String

result = sw.ToString()

result = Replace(result, "xmlns:asp=" & """" & "remove" & """", "")

Dim ctrl As Control

ctrl = Page.ParseControl(result)

myTree.Controls.Add(ctrl)

---------------------------------------------------------

In this case all validators page are work,BUT problem that I CANN'T use
Server.MapPath ("file.xml") ***

I HAVE get XML document as output result of the function *

Thanks

Forum

unread,
Jul 9, 2003, 9:12:27 AM7/9/03
to

KathyB

unread,
Jul 9, 2003, 7:52:24 PM7/9/03
to
Hi. I've never seen files named filename.xslt -- are you sure it's not file.xsl?

kathy


"Forum" <ju...@abgsystems.com> wrote in message news:<eKGlAvh...@tk2msftngp13.phx.gbl>...

Kirk Allen Evans

unread,
Jul 10, 2003, 1:45:35 PM7/10/03
to
I think you should be adding the parsed controls to Page.Controls instead of
Label.Controls. I have an example of this on my web log
(http://weblogs.asp.net/kaevans/posts/2795.aspx), but not with validation
controls. . I will try to whip up a quick example to confirm it.


--
Kirk Allen Evans
www.xmlandasp.net
Read my web log at http://weblogs.asp.net/kaevans


"Forum" <ju...@abgsystems.com> wrote in message
news:eKGlAvh...@tk2msftngp13.phx.gbl...

Kirk Allen Evans

unread,
Jul 10, 2003, 1:59:54 PM7/10/03
to
Here is the Page_Load method for the web form:

XmlDocument doc = new XmlDocument();
//Load a summy document just for transforming. Content is not relevant
// in this example.
doc.LoadXml("<foo/>");
XslTransform trans = new XslTransform();
trans.Load(Server.MapPath("xslt/dynamiccontrols.xslt"));
System.IO.StringWriter writer = new System.IO.StringWriter();
trans.Transform(doc, null, writer, new XmlUrlResolver());
string result = writer.ToString();
result = result.Replace("xmlns:asp=\"Remove\"",string.Empty );
Control form = Page.FindControl("Form1");
form.Controls.Add(Page.ParseControl(result));


The .aspx view is empty, it just has the empty form tag. This is what you
need to add all of the parsed controls to.

<%@ Page language="c#" Codebehind="DynamicControls.aspx.cs"
AutoEventWireup="false" Inherits="ExampleWeb.DynamicControls" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DynamicControls</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
&nbsp;
</form>
</body>
</HTML>


The XSLT looks like the following:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="Remove">
<xsl:template match="/">
<!--div required for well-formed XML output -->
<div>
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 104px; POSITION:
absolute; TOP: 104px"
runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" style="Z-INDEX:
102; LEFT: 280px; POSITION: absolute; TOP: 104px"
runat="server" ErrorMessage="RequiredFieldValidator"
ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 240px; POSITION:
absolute; TOP: 144px" runat="server"
Text="Button"></asp:Button>
</div>
</xsl:template>
</xsl:stylesheet>


When I run this example, I get the textbox, button, and validation control,
and validation works as expected.


--
Kirk Allen Evans
www.xmlandasp.net
Read my web log at http://weblogs.asp.net/kaevans


"Forum" <ju...@abgsystems.com> wrote in message
news:eKGlAvh...@tk2msftngp13.phx.gbl...

0 new messages