0

我在按钮单击事件中有此代码。问题是我想在每次文本框得到验证和提交时显示文本“线程已成功添加”,并希望在提交后清除该标签。有没有办法做到这一点?

protected void BtnThread_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            LabelThread.ForeColor = System.Drawing.Color.Purple;
            LabelThread.Text = "Thread has been added successfully";
        }

        else
        {

            LabelThread.Text = "Thread couldnot not be added";

        }

        Thread obj = new Thread();
        obj.Insert_thread = TxtBoxThread.Text;

        int j = obj.insertmethod();

        TxtBoxThread.Text = "";
4

2 回答 2

0
protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
   {

    }
   LabelThread.Text = String.Empty;
}
于 2013-09-17T02:56:20.767 回答
0

尝试写入没有 ViewState 的元素。我相信它的内容不会在回发后持续存在,只会在设置后立即出现。

ASPX:

<div id="MessageBox" runat="server"></div>

在您的 BtnThread_Click 事件中:

MessageBox.InnerText = "Thread has been added successfully";
于 2013-09-16T21:54:52.770 回答