Display Message when Registration hits 0
Current Background: I have a ASP.NET VB form connected to a database. In the database, there is a field called TourCount. This count decrimates by 1 everytime a user submits a form.
Goal: When the TourCount reaches 0, all registrations must close. However, at the moment, TourCount continues to decrimate into negative numbers. When TourCount reaches 0, I would like a message to appear above the form saying "Registration Closed".
Current Attempt: I have tried a few things, but I'm not sure where it's going. I don't receive a config error message, but it's never functioning correctly either. I'm not sure where or what type of script I should be using. My logic says, when TourCount is less than or equal to zero, display a text string via the id called "Message".
<asp:SqlDataSource id="SqlDataSrcTourCount" runat="server" ConnectionString="<%$ ConnectionStrings:recruitmentConnectionString %>" SelectCommand = "SELECT [TourCount] FROM [tourdates] WHERE [TourType] = @TourType AND [TourDatesAvailable] = @TourDates" ProviderName="System.Data.SqlClient" UpdateCommand="UPDATE [tourdates] SET [TourCount] = ([TourCount] - 1) WHERE [TourType] = @TourType AND [TourDatesAvailable] = @TourDates">
<SelectParameters>
<asp:Parameter Name="TourType" DefaultValue="JobFair"></asp:Parameter>
<asp:Parameter Name="TourDates" Type="String"></asp:Parameter>
</SelectParameters>
<UpdateParameters>
<asp:parameter Name="TourType" DefaultValue="JobFair"></asp:Parameter>
<asp:parameter Name="TourDates" Type="String"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<script type="text/javascript">
If (TourCount <= 0) {
document.getElementById("Message").style.display = "inline";
return true;
}
else {
document.getElementById("Message").style.display = "none";
return false;
}
</script>
In the HTML: <span id="Message">-Closed-</span>
If anyone could provide me with some insight about how to proceed, I would truly appreciate your help. Thank you so much for your开发者_高级运维 time in reading.
I'm wondering, why are you using javascript for this?
If I was you I'd simply get the TourCount on PageLoad Navigate to your closed.asmx if TourCount = 0 else when they hit the Submit button get the TourCount again (it could've changed in the meantime) If still > 0 do the registration and reduce TourCount If 0 navigate to the 'too slow slowpoke' page.
The only thing I'd use javascript for is dynamically refreshing TourCount every x seconds and automatically navigating to closed.asmx when it hits 0.
精彩评论