我正在开发一个简单的注册系统,其中所有事件都将列在 GridView 中,用户可以通过单击事件旁边显示的注册按钮来单击事件中的注册。工作正常,但我只有一个问题,如下所示:当用户尝试注册他已经在其中注册的事件之一时,他将在 GridView 下收到一条错误消息。问题当他在另一个事件中成功注册时,此消息将一直显示。我想要的只是显示这条消息几秒钟。
那么该怎么做呢?
这是我在 ASP.NET 中的代码:
<asp:GridView ID="ListOfAvailableEvents_GrivView" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" AllowPaging="True" PageSize="10"
onrowdatabound="ListOfAvailableEvents_GrivView_RowDataBound">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" CssClass="generaltext" />
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:LinkButton ID="lnkTitle" runat="server" CssClass="button" Text="Book →" OnClick="lnkTitle_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" />
<asp:BoundField DataField="StartDateTime" HeaderText="Start Date & Time" SortExpression="StartDateTime" />
<asp:BoundField DataField="EndDateTime" HeaderText="End Date & Time" SortExpression="EndDateTime" />
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle Font-Bold="True" CssClass="complete" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EmptyDataTemplate><h2>No Events Available</h2></EmptyDataTemplate>
</asp:GridView>
<span id="errorSpan" runat="server" style="color:Red;"></span>
<asp:Button ID="btnModalPopUp" runat="server" Style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="modalPopupExtender1" runat="server" TargetControlID="btnModalPopUp"
PopupControlID="pnlPopUp" BackgroundCssClass="popUpStyle" PopupDragHandleControlID="panelDragHandle"
OkControlID="OKButton">
</ajaxToolkit:ModalPopupExtender>
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Panel ID="pnlPopUp" runat="server" CssClass="popUpStyle">
<%--<asp:Label ID="lblQuestion" runat="server" Text="Are you sure you want to register in" />--%>
<table class="tableClass" width="400px">
<tr>
<th valign="middle" colspan="2" align="center" bgcolor="#99CCFF" style="font-weight: bold;
font-size: larger">
Event Details
</th>
</tr>
<tr>
<td class="thClass">
Title:
</td>
<td class="tdClass">
<asp:Label ID="lblTitle" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="thClass">
Description:
</td>
<td class="tdClass">
<asp:Label ID="lblDescription" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="thClass">
Location:
</td>
<td class="tdClass">
<asp:Label ID="lblLocation" runat="server" />
</td>
</tr>
<tr>
<td class="thClass">
Start Date & Time:
</td>
<td class="tdClass">
<asp:Label ID="lblStartDateTime" runat="server" />
</td>
</tr>
<tr>
<td class="thClass">
End Date & Time:
</td>
<td class="tdClass">
<asp:Label ID="lblEndDateTime" runat="server" />
</td>
</tr>
</table>
<center>
<asp:Button ID="confirmButton" runat="server" Text="Register" OnClick="btnSendConfirmationEmail_Click" />
<asp:Button ID="OKButton" runat="server" Text="Cancel" /></center>
</asp:Panel>
C#代码隐藏:
protected void btnSendConfirmationEmail_Click(object sender, EventArgs e)
{
int eventID = Convert.ToInt32(HiddenField1.Value);
if (!UserHasBooking(userNetworkID, eventID))
{
checkUserID(userNetworkID, eventID);
SmtpClient sc = new SmtpClient("Mail Server");
StringBuilder sb = new StringBuilder();
MailMessage msg = new MailMessage();
//Variables for retrieving the Booking Information
string title = lblTitle.Text;
string description = lblDescription.Text;
string location = lblLocation.Text;
string startDateTime = lblStartDateTime.Text;
string endDateTime = lblEndDateTime.Text;
//Message Information
string toAddress = userNetworkID + "@mailserver.com";
string fromAddress = "Test@MailServer.com";
string mailSubject = "Registration Notification: " + title + " (" + startDateTime + " - " + endDateTime + ")";
string messageBody = "............";
try
{
msg.To.Add(toAddress);
msg.From = new MailAddress(fromAddress, "Registration System");
msg.Subject = mailSubject;
msg.Body = messageBody;
msg.IsBodyHtml = true;
sc.Send(msg);
}
catch (Exception ex)
{
throw ex;
// something bad happened
//Response.Write("Something bad happened!");
}
finally
{
if (msg != null)
{
msg.Dispose();
}
}
}
else
{
errorSpan.InnerText = "You already have a booking in this event";
}
}
错误信息是:errorSpan.InnerText = "您已经预订了此活动";
那么如何解决呢?