这可能很简单,但我无法弄清楚。我在updatePanel中有一个简单的联系表单,当用户按下发送按钮时,标签应该在发送之前出现。完成后应该说像Message Send。
Application.DoEvents()可以解决问题,但是,我们在asp.net中... 我尝试了多线程,但仍然将lblMessageSend文本更改为"发送电子邮件..请等待.."消息发送后。除了那些不是ThreadSafe之外,还没有工作......
protected void btnSend_Click(object sender, EventArgs e)
{
lblMessageSend.Text = "Sending e-mail.. Please Wait..";
lblMessageSend.Visible = true;
ThreadStart t1 = new ThreadStart(SendMessage);
Thread thr = new Thread(t1);
thr.Start();
}
private void SendMessage()
{
//do some sending stuff
lblMessageSend.Text = Resources.strings.quotationMessage;
}
HTML
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSend" runat="server" Text="Send" ValidationGroup="Form" TabIndex="12" OnClick="btnSend_Click" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="lblMessageSend" runat="server" Visible="false" Text="<%$ Resources:strings, quotationMessage%>"></asp:Label>
</td>
</tr>
答案 0 :(得分:1)
Thx @Black Baron。
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSend" runat="server" Text="Send" ValidationGroup="Form" OnClientClick="ChangeLabelText();" TabIndex="12" OnClick="btnSend_Click" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="lblMessageSend" runat="server" Text=""></asp:Label>
</td>
</tr>
使用Javascript:
<script type="text/javascript">
if (Page_ClientValidate()) { //to check if the validationFields are validated..
document.getElementById('<%= lblMessageSend.ClientID %>').innerHTML = 'Sending.. Please wait..';
}
</script>
老实说,我仍然有点失望,因为我仍然需要使用javascript来完成任务。但它有效,这很重要。