Home > ASP.NET > How to use ASP.NET controls inside XSLTs

How to use ASP.NET controls inside XSLTs


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
    exclude-result-prefixes="msxsl vt">

    <xsl:output method="html" version="4.0"/>

    <xsl:template match="/">
            <asp:TextBox runat="server"


private void Page_Init(object sender, System.EventArgs e)
     XsltArgumentList xsltArgs = new XsltArgumentList();
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     XslCompiledTransform xml = new XslCompiledTransform();
     xml.Transform(Server.MapPath("test.xml"), xsltArgs, sw);

    string html = sb.ToString();
    html = html.Replace("xmlns:asp=\"remove\"", String.Empty);//Retirar o namespace
    Control ctrl = ParseControl(html);//Get the control collection
    OutPutPlace.Controls.Add(ctrl);// OutPutPlace is a placeholder

    // Register some events
    TextBox txtname = OutPutPlace.FindControl("txtname") as TextBox;
    // Find a Textbox that was inside the XSLT


<%@ Page Trace="true" language="c#"
    Codebehind="C.aspx.cs" AutoEventWireup="false" Inherits="default" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

        <form id="Form1" method="post" runat="server">
              <asp:PlaceHolder ID="OutPutPlace" runat="server"></asp:PlaceHolder>

Categories: ASP.NET
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: