2012-03-05 80 views
3
页面

上我有ASP代码:使用C#编写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> 

但文字结束了附近的某处页的开头,我并不想让它去。我怎样才能做到这一点?

回答

4

您输出显示在页面的顶部,因为您的页面内容放置到页面之前您的页面内容正在执行Response.Write()

为什么not just

<%="<h1>some text</h1>" %> 

您可以创建一个将返回一个字符串,并从*.as?x文件调用它的方法:

protected string GetMyCoolHtml() 
{ 
    return "<h3>this is my text</h3>"; 
} 

.... 

<%= GetMyCoolHtml() %> 
+0

它适用于静态短语。但后来我把'<%= GetPhrase(“some_text_key”,“

一些文本

”); %>'和我得到一个“)预期”的错误。为什么? – hardmax 2012-03-05 11:31:16

+0

检查你方法的签名。你的代码适用于我,当方法被decalred为'protected string GetPhrase(string key,string h1Text){return key +“
”+ h1Text; }' – 2012-03-05 11:34:23

+3

删除';'。当使用<%= %>来显示东西时,不;是期待。 – Abbas 2012-03-05 11:34:25

1

文字控件添加到您的网页,写任何你想要的在服务器端。