我在按钮点击事件中有这个代码。问题是我希望每次文本框得到验证和提交时都显示“已成功添加线程”文本,并希望在提交后清除该标签。有没有办法做到这一点?
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 = "";
答案 0 :(得分:0)
尝试写入没有ViewState的元素。我相信它的内容不会在帖子后面持续存在,并且只会在设置后立即出现。
ASPX:
<div id="MessageBox" runat="server"></div>
在你的BtnThread_Click事件中:
MessageBox.InnerText = "Thread has been added successfully";
答案 1 :(得分:0)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
LabelThread.Text = String.Empty;
}