我有这样的 ASP 代码:
<ext:Panel ID="pnlHelp" CtCls="help-panel" AnimCollapse="true"">
<Content>
<h1>some text</h1>
<p>
More text[...]
</p>
</Content>
</ext:Panel>
我想生成 <Content>
使用 C# 动态标记。我试过这个,就像使用常规 HTML 标签一样:
<ext:Panel ID="pnlHelp" CtCls="help-panel" AnimCollapse="true"">
<Content>
<% Response.Write("<h1>some text</h1>"); %>
<p>
More text[...]
</p>
</Content>
</ext:Panel>
但文本最终出现在页面开头附近的某个地方,我不希望它出现。我该怎么做?
最佳答案
您的输出出现在页面顶部,因为您的 Response.Write()
在页面内容被响应之前被执行。
为什么 not just
<%="<h1>some text</h1>" %>
您可以创建一个返回字符串的方法,并从您的 *.as?x
文件中调用它:
protected string GetMyCoolHtml()
{
return "<h3>this is my text</h3>";
}
....
<%= GetMyCoolHtml() %>
关于c# - 使用C#在页面上编写ASP代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9565729/