Click here to Skip to main content
15,886,724 members
Articles / Web Development / ASP.NET

Manage ASP.NET Server Controls, Event Handlers, and Server-Side Validation Using XML and XSLT

Rate me:
Please Sign up or sign in to vote.
4.87/5 (16 votes)
18 Apr 2008CPOL3 min read 47.6K   489   33  
An article on managing ASP.NET server controls, event handlers, and server-side validation using XML and XSLT.
<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:param name="employeeId"/>-->
  <xsl:param name="employeeId"/>
  <xsl:template match="/root">
    <xsl:for-each select="Employee">
      <xsl:if test="@Id = $employeeId">
       
      <table width="100%" border="0" cellspacing="0" cellpadding="0"  bgcolor="#FFFFFF">
        <tbody>
          <tr>
            <td>
              <xsl:apply-templates select="Address">
                <!--<xsl:with-param name="count" select="$count"/>-->
              </xsl:apply-templates>
              
            </td>
          </tr>
          <tr>
            <td>&#160;</td>
          </tr>
          <tr>
            <td align="right">
              <span style="margin-right:20%">
                <asp:Button ID="btnSaveAddress" runat="server" BackColor="White"
              BorderColor="DeepSkyBlue" BorderStyle="Solid" BorderWidth="1px" Font-Names="Tahoma"
              Font-Size="10pt" Text="Save Data" />
              </span>
              <span>&#160;</span>
            </td>
          </tr>
        </tbody>
      </table>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="HomeAddress" match="/root/Employee/Address">
    <table width="100%">
      <tr>
        <td height="30" colspan="2" align="left">
          <strong>
            <xsl:value-of select="@Caption"/>
          </strong>
        </td>
      </tr>
      <tr>
        <td height="2" colspan="2" align="left" bgcolor="#CCCC99"></td>
      </tr>
      <tr>
        <td width="50%" height="30" align="left" valign="top">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td colspan="4" height="4"></td>
            </tr>

            <tr>
              <xsl:for-each select="child::*">
                <xsl:variable name="rowindex" select="position()"></xsl:variable>
                <td align="left" valign="top">
                  <table cellpadding="4">
                    <tr>
                      <td colspan="4" height="28" align="left" valign="top">
                        <strong>
                          <xsl:value-of select="@Caption"/>
                        </strong>
                      </td>
                    </tr>

                    <xsl:for-each select="child::*">
                      <xsl:variable name="varType" select="@Type"></xsl:variable>
                      <xsl:variable name="isRequired" select="@Required"></xsl:variable>
                      <xsl:variable name="varId" select="translate(concat(concat(concat(@Caption,'_'),$rowindex),position()),' ','_')"></xsl:variable>
                      <xsl:variable name="up" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
                      <xsl:variable name="lo" select="'abcdefghijklmnopqrstuvwxyz'"/>
                      <tr>
                        <td height="28" align="left" valign="top">
                          <xsl:value-of select="@Caption"/>
                        </td>
                        <td colspan="3" align="left" valign="top" height="28">
                          <xsl:choose>
                            <xsl:when test="translate($varType,$up,$lo)='countryddl'">
                              <asp:DropDownList id="{concat('ddlCountry',$rowindex)}" runat="server" DataTextField="Text" DataValueField="Value">
                                <asp:ListItem value="{.}">
                                  <xsl:value-of select="."/>
                                </asp:ListItem>
                              </asp:DropDownList>
                            </xsl:when>
                            <xsl:otherwise>
                              <asp:TextBox ID="{$varId}" runat="server" Text="{.}" width="205px" ></asp:TextBox>
                              <xsl:if test="translate($isRequired,$up,$lo)='yes'">
                                <asp:RequiredFieldValidator ErrorMessage=" Required Field" runat="server" ControlToValidate="{$varId}" />
                              </xsl:if>
                            </xsl:otherwise>
                          </xsl:choose>
                        </td>
                      </tr>
                    </xsl:for-each>
                  </table>
                </td>
              </xsl:for-each>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </xsl:template>
</xsl:stylesheet>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Desme Inc
Bangladesh Bangladesh
Ehsanul Haque is a Software Engineer, who is dedicated to Microsoft .NET based development. He is involved with several US based software projects from his country. Already he has completed few projects, which are being used by several users of different countries, such as USA, Japan, and Bangladesh. While developing and managing a team, he maintains a set of well defined engineering practices developed by him and other online developer community. Beside software development, he has also written several technical articles.

When not engaged with technical stuffs, he likes to pass time with his friends, and family members, listens music, watching TV, travel or by reading books.

Comments and Discussions