Page.FindControl?
I am working on a page that inherits a Base Page. The aspx page includes a control that uses xslt for to transform an xml document to html markup. Within that document I am using the following:
<xsl:template match="Headline">
<h1 runat="server" id="h1" clas开发者_如何学编程s="article-heading">
<xsl:value-of select="text()"/>
</h1>
</xsl:template>
I am trying to get the get the value of the h1 to set it to page.title, can this be done with page.findControl ?
XSLT within a browser tends to be interpreted on the client-side, not the server side. Using Page.FindControl to find the content of the H1 won't get you too far, as all that will return is the literal <xsl:value-of...> statement.
The best approach is to also open the XML document within the codebehind on the server and set the Page Title from there.
you can use javascript to find h1 on clientside then set it to the document.title
Unfortunately no, because your <h1>
element never gets added to control tree on the server. Even though you have runat="server"
ASP.NET doesn't parse HTML resulting from XSLT transformation.
You would have to resort to parsing your XML to get the heading. With XPath it should be easy.
精彩评论