Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4346570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:11:26+00:00 2026-05-21T12:11:26+00:00

I’m new to XML/XSLT. What I did is I’ve created an XML file with

  • 0

I’m new to XML/XSLT. What I did is I’ve created an XML file with some list, and used XSLT to transform it.

Here’s the code:

protected void Page_Load(object sender, EventArgs e)
{
    this.form1.Controls.Add(Xml1);

    Button btnSubmit = new Button();
    btnSubmit.Text = "Submit";
    this.form1.Controls.Add(btnSubmit);
    btnSubmit.Click += new System.EventHandler(btnSubmit_Click);

    Xml1.DocumentSource = "~/xml/XML_F52E2B61-18A1-11d1-B105-00805F49916B1.xml";
    Xml1.TransformSource = "~/KPI_table.xslt";

    //Together, the Xml1.DocumentSource and the Xml1.TransformSource will display a 
    //list of items with a dropdownlist each.
}

private void btnSubmit_Click(Object sender, System.EventArgs e)
{
    foreach (Control c in form1.Controls) //or is it possible to access the controls
                                          //inside XML1 here?
    {
         //This is where I need to access the controls inside the Xml1 object.
    }
}

When I tried to debug/trace the program, I found out that the foreach loop only saw 3 controls (System.Web.UI.LiteralControl, System.Web.UI.WebControls.Xml, and System.Web.UI.WebControls.Button). And I can’t find a way to get into the controls inside the XXML object/control so I can get the SelectedValue of the DropdownLists/options. How will I be able to access the controls inside the Xml1 object/control??

Update 2: Here is the generated HTML code:

<body>
    <form method="post" action="Main.aspx" id="form1">
      <div class="aspNetHidden">
        <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"     value="/wEPDwULLTE2MTY2ODcyMjlkZCn80c6JtFOE8ISKTFArpEqY4qC8tA9LkNAs7gn6n6Zu" />
     </div>    
   <div class="aspNetHidden">    
      <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLm9oEzAqDAiY0LmVXxKZ8kddyJnX1LgEhJf4qGDJE14PdWmMUYC7LLAAk=" />
   </div>
   <div>
   </div>
   <table id="tbl1" runat="server" xmlns:asp="remove">    
     <tr>
       <td>BEHAVIOR</td>
     </tr>
     <tr>
       <td>Stellar KPIs</td>
     </tr>
     <tr>    
       <td>Customer Demeanor at Start of call:</td>
       <td>
         <select id="ddl_3" runat="server" AutoPostBack="true"    onchange="getvalue(this);">
           <option value="0">Select</option>
           <option value="A">                Audibly Happy</option>
           <option value="N">                Neutral</option>    
           <option value="I">                Irate</option>
           <option value="R">                At risk</option>
        </select>
      </td>
    </tr>
    <tr>
    <td>Customer Demeanor at End of call:</td>    
    <td>
      <select id="ddl_8" runat="server" AutoPostBack="true" onchange="getvalue(this);">
        <option value="0">Select</option>
        <option value="A">                Audibly Happy</option>
        <option value="N">                Neutral</option>
        <option value="I">                Irate</option>    
        <option value="R">                At risk</option>
      </select>
    </td>
  </tr>

Update 3: here’s the screenshot of the HTML code rendered: screenshot

Update 4: here’s the XSLT file

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="remove" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="html" indent="yes"/>
    <xsl:template name="home" match="/">
        <table id="tbl1" runat="server">
            <xsl:for-each select="ProgramKPI/KPIs">
                <xsl:variable name="varKPI" select="KPI_ID"/>
                <xsl:choose>
                    <xsl:when test="Level = '1'">
                        <tr>
                            <td>
                                <xsl:value-of select="Attribute"/>
                            </td>
                        </tr>
                    </xsl:when>
                    <xsl:when test="Level = '2'">
                        <tr>
                            <td>
                                <xsl:value-of select="Attribute"/>
                            </td>
                        </tr>
                    </xsl:when>
                    <xsl:when test="Level = '3'">
                        <tr>
                            <td>
                                <xsl:value-of select="Attribute"/>
                            </td>
                            <xsl:variable name="ddl_name" select="concat('ddl_', KPI_ID)"/>
                            <td>
                                <xsl:element name="select">
                                    <xsl:attribute name="id"><xsl:value-of select="concat('ddl_', KPI_ID)"/></xsl:attribute>
                                    <xsl:attribute name="runat">server</xsl:attribute>
                                    <xsl:attribute name="AutoPostBack">true</xsl:attribute>
                                    <xsl:attribute name="onchange">getvalue(this);</xsl:attribute>
                                    <xsl:element name="option">
                                        <xsl:attribute name="value"><xsl:value-of select="0"/></xsl:attribute>
                                        <xsl:value-of select="'Select'"/>
                                    </xsl:element>
                                    <xsl:for-each select="//Parent_KPI[.=$varKPI]">
                                        <xsl:element name="option">
                                            <xsl:attribute name="value"><xsl:value-of select="preceding-sibling::AttributeCode"/></xsl:attribute>
                                            <xsl:value-of select="preceding-sibling::Attribute"/>
                                        </xsl:element>
                                    </xsl:for-each>
                                </xsl:element>
                                <!--<asp:DropDownList id="{concat('ddl_', KPI_ID)}" runat="server">
                        <asp:ListItem value="0">  Select  
                        </asp:ListItem>

                        <xsl:for-each select="//Parent_KPI[.=$varKPI]">
                          <asp:ListItem>
                            <xsl:attribute name="value">
                              <xsl:value-of select="preceding-sibling::AttributeCode"/>
                            </xsl:attribute>
                            <xsl:value-of select="preceding-sibling::Attribute"/>
                          </asp:ListItem>
                        </xsl:for-each>
                      </asp:DropDownList>-->
                            </td>
                        </tr>
                    </xsl:when>
                </xsl:choose>
            </xsl:for-each>
        </table>
    </xsl:template>
</xsl:stylesheet>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:11:27+00:00Added an answer on May 21, 2026 at 12:11 pm

    Try checking for child controls. Ideally you’d do this recursively but as a quick and dirty way:

    private void btnSubmit_Click(Object sender, System.EventArgs e)
    {
        foreach (Control c in form1.Controls) 
        {            
            if (c.HasControls())
            {
                foreach (Control child in c)
                {
                    //Access Child controls here
                }
            }
        }
    }
    

    That being said I’m unsure of adding controls to the page via XML this way.

    Also you may want to add the controls earlier in the page lifecycle possibly the onInit event and make sure to not add the controls again on postback.

    UPDATE: In light of John Sanders answer:
    you could go old school and use the request object to access values, not a .net but it should work. E.g:

    string dropDownValue = Request.Form["yourDropDownID"];
    

    Update 2
    To Iterate through the values posted back you can do the following:

    private void btnSubmit_Click(Object sender, System.EventArgs e)
    {
        foreach (string key in Request.Form.AllKeys)
        {
            Response.Write (string.Format("{0} => {1}<br />", key, request.Form[key]));
        }
    }
    

    However, to do this you will need to make sure that the rendered HTML has a name attribute for the form elements. Change your XSLT for the select element to the following:

    <xsl:element name="select">
       <xsl:attribute name="id">
          <xsl:value-of select="concat('ddl_', KPI_ID)"/>
       </xsl:attribute>
       <xsl:attribute name="name">
          <xsl:value-of select="concat('ddl_', KPI_ID)"/>
       </xsl:attribute>
       <xsl:attribute name="onchange">getvalue(this);</xsl:attribute>
       <xsl:element name="option">
          <xsl:attribute name="value">
             <xsl:value-of select="0"/>
          </xsl:attribute>
          <xsl:value-of select="'Select'"/>
    </xsl:element>
    

    Note the inclusion of the name attribute and the removal of the runat server and auto postback attributes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.