[英]How to show a HTML ASP Code on a label sending from Code-Behind
I'm having a problem, which I want to send ASP HTML code to a Label from a method on Code-Behind, to make the label shows dynamically the HTML code on screen. 我遇到了一个问题,我想通过Code-Behind上的方法将ASP HTML代码发送到Label,以使标签在屏幕上动态显示HTML代码。 But when I send it only works when the code Isn't <asp:>
just HTML. 但是,当我发送时,仅当代码不是<asp:>
只是HTML时,它才有效。
public void FillPage(int size)
{
StringBuilder sb = new StringBuilder();
sb.Append(string.Format(@"<asp:LinkButton ID='LinkButton1' runat='server' OnClick='LinkButton1_Click'><asp:Table ID='tableProd' class='tableProduto' runat='server'>
<asp:TableRow>
<asp:TableCell RowSpan='2' Width='155px'><img src='images/categorias/bebida.png' /></asp:TableCell>
<asp:TableCell Width='550px'>Nome</asp:TableCell>
<asp:TableCell RowSpan='2'>Preço</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Width='550px'><div class='divTexto'><p>Descrição</p></div></asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:LinkButton> "));
lblTexto.Text = sb.ToString();
}
}
It doesn't works. 它不起作用。 But when I do the following code it works: 但是,当我执行以下代码时,它可以工作:
public void FillPage(int size)
{
StringBuilder sb = new StringBuilder();
sb.Append(string.Format(@"<asp:LinkButton ID='LinkButton1' runat='server' OnClick='LinkButton1_Click'><table ID='tableProd' class='tableProduto' runat='server'>
<tr>
<td RowSpan='2' Width='155px'><img src='images/categorias/bebida.png' /></td>
<td Width='550px'>Nome</td>
<td RowSpan='2'>Preço</td>
</tr>
<tr>
<asp:TableCell Width='550px'><div class='divTexto'><p>Descrição</p></div></td>
</tr>
</table>
</asp:LinkButton> "));
lblTexto.Text = sb.ToString();
}
}
But I need the controls of LinkButton, which isn't working. 但是我需要LinkButton的控件,该控件无法正常工作。
You can't do that. 你不能那样做。
"ASP Codes" can only be interpreted on the server. “ ASP代码”只能在服务器上解释。 By putting them in the label, you're requiring the browser to understand them - it won't. 通过将它们放在标签中,您需要浏览器理解它们-不会。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.