0

我目前正在尝试创建一个语句,如果它返回 false 则标签将显示在页面上并显示错误消息。我试过使用Response.Write没有结果。

if (bannedDomainText.Text.Contains("."))
    File.AppendAllText(MapPath(FILE_PATH), "\r\n" + bannedDomainText.Text);
else
    Response.Write("<label>This isn't working!</label>");
4

2 回答 2

2

html

<asp:Label ID="ErrorMessage" Visible="false"></asp:Label>

代码

if (bannedDomainText.Text.Contains("."))
    File.AppendAllText(MapPath(FILE_PATH), "\r\n" + bannedDomainText.Text);
else
{
    Message.Text =  "This is working";
    Message.Visible = true;
}
于 2012-11-07T09:14:27.350 回答
1

定义服务器端标签并将消息分配给其文本属性。You can hide this label or set its text to empty string when you do not want to show the message.

在 HTML 中

<asp:Label id="lblMessage" runat="server" />

在代码后面

if (bannedDomainText.Text.Contains("."))
    File.AppendAllText(MapPath(FILE_PATH), "\r\n" + bannedDomainText.Text);
else
    lblMessage.Text =  "This is working";
于 2012-11-07T09:10:33.340 回答