<%@ Control Language="VB" ClassName="RSVP_PedBike_Promo_Test01" Debug="true" AutoEventWireup="true" %>
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
'If (Not IsPostBack) Then
'Dim lb As Label
'lb = RSVPForm1.FindControl("OrderTotalAmount2")
' dd.Items.Add(New ListItem("Home Rule", "Home Rule"))
' dd.Items.Add(New ListItem("General Law", "General Law"))
'End If
End Sub
Protected Sub RSVPForm1_CalculateTotalEvent(ByVal e As HGACServerControls.CalculateTotalEventArgs)
If (IsPostBack) Then
'Dim totalBox As HiddenField
Dim totalBox As TextBox
'find the control
totalBox = RSVPForm1.FindControl("hdnTotal")
'Throw an exception if we could not find the total
'If (totalBox Is Nothing) Then
'Throw New Exception("Could not get total")
'End If
Try
e.Total = CDec(Page.Request.Form(totalBox.UniqueID))
Catch
' If Conversion does not work set to zero
e.Total = New Decimal(0)
End Try
End If
End Sub
Protected Sub RSVPForm1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
'Dim hdnTotal As HiddenField
Dim hdnTotal As TextBox = RSVPForm1.FindControl("hdnTotal")
' Dim totalBox As TextBox = RSVPForm1.FindControl("hdnTotal")
'Request.Form("hdnTotal")
'hdnTotal = RSVPForm1.FindControl("hdnTotal")
'hdnTotal.Text = ("25")
'totalBox.text = ("35")
If Not (hdnTotal Is Nothing) Then
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "hdnTotalIdScript", "var hdnTotalId = '" + hdnTotal.ClientID + "';", True)
End If
End Sub
Protected Sub btnVerifyPromos_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' Creates myConnection as a new sqlconnection and sets it equal to DSN_PROD
Dim myConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("DSN_PROD").ConnectionString)
myConnection.Open()
' Build a sql statement string
Dim query1 As String = "Select PromoCode, DiscountValue FROM tblPromoCodes WHERE PromoCode = @PromoCode"
' Initialize the sqlCommand with the new sql string.
Dim Command1 As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(query1, myConnection)
' Declare txtPromoCode As TextBox and find in the form.
Dim txtPromoCode As TextBox = DirectCast(RSVPForm1.FindControl("txtPromoCode"), TextBox)
Dim lbl_Discount As Label = DirectCast(RSVPForm1.FindControl("lbl_Discount"), Label)
Dim txtDiscountValue As TextBox = DirectCast(RSVPForm1.FindControl("txtDiscountValue"), TextBox)
Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)
' Command1.Parameters.AddWithValue("@DiscountValue", lbl_Discount.Text)
'Command1.Parameters.AddWithValue("@DiscountValue", txtDiscountValue.Text)
'If there is a single quote in the string below (Dim PromoCode As String = ""), this causes validation of the to fail
Dim PromoCode As String = ""
'Dim DiscountValue As Int16 = "0"
Dim DiscountValue As Integer = 0
'Create new parameters for the sqlCommand object and initialize them to the input values.
'Execute the command
Dim reader As System.Data.SqlClient.SqlDataReader = Command1.ExecuteReader
If reader IsNot Nothing AndAlso reader.HasRows Then
reader.Read()
PromoCode = reader.GetString(0)
DiscountValue = reader.GetInt32(1)
End If
' Display whether the page passed validation.
Dim lbl_message As Label = DirectCast(RSVPForm1.FindControl("lbl_message"), Label)
If Not String.IsNullOrEmpty(PromoCode) Then
lbl_message.Text = "Promo Code Accepted."
'Response.Write("--" + PromoCode.ToString() + "Accepted")
lbl_Discount.Text = "Discount Applied."
txtDiscountValue.Text = DiscountValue.ToString()
Else
lbl_message.Text = "Promo Code Invalid."
'Response.Write("-- Not Accepted")
lbl_Discount.Text = "Discount Not Applied."
txtDiscountValue.Text = "0"
End If
' args.IsValid = False
If Not String.IsNullOrEmpty(PromoCode) Then
lbl_message.Text = "Promo Code Accepted."
' Response.Write("--" + PromoCode.ToString() + "Accepted")
lbl_Discount.Text = "Discount Applied."
txtDiscountValue.Text = DiscountValue.ToString()
Else
lbl_message.Text = "Promo Code Invalid."
'Response.Write("-- Not Accepted")
lbl_Discount.Text = "Discount Not Applied."
txtDiscountValue.Text = "0"
End If
'******* Calculate the event price if PromoCode isValid *********
Dim txtTotal As TextBox = DirectCast(RSVPForm1.FindControl("txtTotal"), TextBox)
Dim txtNumberofTickets As TextBox = DirectCast(RSVPForm1.FindControl("txtNumberofTickets"), TextBox)
Dim hdnTotal As TextBox = DirectCast(RSVPForm1.FindControl("hdnTotal"), TextBox)
If Not String.IsNullOrEmpty(txtNumberofTickets.Text) Then
Dim nt As Integer = Convert.ToInt32((txtNumberofTickets.Text))
Dim price As Integer = nt * 25
'to have a percent discount from price, use the formula below like this:
'Dim total As Decimal = price - (price * DiscountValue / 100)
'to have a hard-dollar discount from price, use the formula above like this:
Dim total As Decimal = price - DiscountValue
txtTotal.Text = total.ToString()
hdnTotal.Text = total.ToString()
Else
txtTotal.Text = "0"
End If
myConnection.Close()
End Sub
</script>
<div style="text-align:center"></div>
<h3 style="text-align:center"> <br />
<span style="color:#66686d; font-size:20px; font-weight:bold">REGISTRATION PROMO CODE TEST</span><br /> <br /><br />
</h3>
<HGACServerControls:RSVPForm ID="RSVPForm1" runat="server" creditcardonly="false" RSVPContactEmail="luis.hernandez@h-gac.com" RSVPFinancialCode="4000-108" RSVPCode="Registration Promo Code Test" ShowBilling="True" OnCalculateTotalEvent="RSVPForm1_CalculateTotalEvent" ShowBillingTotalLabel="false" OnLoad="RSVPForm1_Load" Width="530px" >
<AdditionalFormControls>
<p style="font-size: x-small; color: red; text-align: center"><br /><br />
* denotes required fields. <br /></p>
<table width="520" cellpadding="0" cellspacing="0" style="border-color:white" border="0">
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px; width:25%">
<asp:Label ID="lblFName" runat="server" AssociatedControlID="tb_FName" Text="First Name:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px; width:25%">
<asp:TextBox ID="tb_FName" runat="server" Width="150px" MaxLength="150" ></asp:TextBox >
</td>
<td style="text-align: left; white-space: nowrap; height: 25px; width:5%">
<span style="color:red">*</span>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px; background-color:white">
<asp:RequiredFieldValidator ID="rfv_FName" runat="server" ControlToValidate="tb_FName" Display="Dynamic" ErrorMessage="First Name is required" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px; background-color:white">
<asp:Label ID="lblLName" runat="server" AssociatedControlID="tbLName" Text="Last Name:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px; background-color:white">
<asp:TextBox ID="tbLName" runat="server" Width="150px" MaxLength="200"></asp:TextBox>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px; background-color:white">
<span style="color:red">*</span>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px; background-color:white">
<asp:RequiredFieldValidator ID="rfv_LName" runat="server" ControlToValidate="tbLName" Display="Dynamic" ErrorMessage="Last Name is required" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="lblTitle" runat="server" AssociatedControlID="tbTitle" Text="Title:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="tbTitle" runat="server" Width="150px" MaxLength="200"></asp:TextBox>
</td>
<td style="text-align: right; white-space: nowrap; height: 25px;"> </td>
<td style="text-align: right; white-space: nowrap; height: 25px;"> </td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="lblOrganization" runat="server" AssociatedControlID="tbOrganization" Text="Organization:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="tbOrganization" runat="server" Width="150px" MaxLength="200"></asp:TextBox>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px;"> <span style="color:red">*</span></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:RequiredFieldValidator ID="rfv_Organization" runat="server" ControlToValidate="tbOrganization" ErrorMessage="Organization is required" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="lblAddress" runat="server" AssociatedControlID="tbAddress" Text="Street:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="tbAddress" runat="server" Width="150px" MaxLength="200"></asp:TextBox>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<span style="color:red">*</span></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:RequiredFieldValidator ID="rfv_Address" runat="server" ControlToValidate="tbAddress" Display="Dynamic" ErrorMessage="Street is required" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator> </td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="lblCity" runat="server" AssociatedControlID="tbCity" Text="City:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="tbCity" runat="server" Width="150px" MaxLength="200"></asp:TextBox>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<span style="color:red">*</span></td>
<td><asp:RequiredFieldValidator ID="rfv_City" runat="server" ControlToValidate="tbCity" Display="Dynamic" ErrorMessage="City is required" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator> </td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px; ">
<asp:Label ID="lblState" runat="server" AssociatedControlID="tbState" Text="State:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="tbState" runat="server" Width="150px" MaxLength="200"></asp:TextBox>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<span style="color:red">*</span></td>
<td><asp:RequiredFieldValidator ID="rfv_State" runat="server" ControlToValidate="tbState" Display="Dynamic" ErrorMessage="State is required" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator> </td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="lblZipCode" runat="server" AssociatedControlID="tbZipCode" Text="Zip Code:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="tbZipCode" runat="server" Width="150px" MaxLength="100"></asp:TextBox></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<span style="color:red">*</span></td>
<td><asp:RequiredFieldValidator ID="rfv_ZipCode" runat="server" ControlToValidate="tbZipCode" Display="Dynamic" ErrorMessage="Zip Code is required" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator> </td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="lblPhone" runat="server" AssociatedControlID="tbPhone" Text="Phone:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="tbPhone" runat="server" Width="150px" MaxLength="200"></asp:TextBox>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<span style="color:red">*</span></td>
<td><asp:RequiredFieldValidator ID="rfv_Phone" runat="server" ControlToValidate="tbPhone" ErrorMessage="Phone is required" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator> </td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="lblCellPhone" runat="server" AssociatedControlID="tbCellPhone" Text="Cell:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="tbCellPhone" runat="server" Width="150px" MaxLength="200"></asp:TextBox>
</td>
<td style="text-align: right; white-space: nowrap; height: 25px;"> </td>
<td style="text-align: right; white-space: nowrap; height: 25px;"> </td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="lblEmail" runat="server" AssociatedControlID="tbEmail" Text="Email:"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="tbEmail" runat="server" Width="150px" MaxLength="200" AutoPostBack="false" ></asp:TextBox></td>
<td style="text-align: left; white-space: nowrap; height: 25px;"> <span style="color:red">*</span></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:RequiredFieldValidator ID="rfv_Email" runat="server" ControlToValidate="tbEmail" ErrorMessage="Email is required" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="rfv_EmailValid" runat="server"
ControlToValidate="tbEmail" ValidationExpression="^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$" Display="Dynamic" ErrorMessage="Enter Valid e-mail"></asp:RegularExpressionValidator> </td>
</tr>
<!--Promo Coupon call starts here /\/\/\/\/\/\/\/-->
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px; background-color:#FFFFFF">
<asp:Label ID="Label2" runat="server" Text="Promo Code:"></asp:Label> </td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="txtPromoCode" Width="150px" runat="server"></asp:TextBox>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px;"> </td>
<td style="text-align: left; white-space: nowrap; height: 25px;"><asp:Button ID="btnVerifyPromos" runat="server" OnClick="btnVerifyPromos_Click" Text="Verify" />
<asp:Label ID="lbl_message" runat="server" Text="" ></asp:Label><br />
<asp:Label ID="lbl_Discount" runat="server" Text="" BackColor="white"></asp:Label>
</td>
</tr>
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="Label1" runat="server" Text="Number of Tickets:"></asp:Label> </td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="txtNumberofTickets" runat="server" Text="1" Width="150px" ReadOnly="true" BackColor="#ebebeb" ></asp:TextBox>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px;"> </td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<!--
<input type="text" name="Regcount" size="2" style="background-color:#FFFFCC" readonly="readonly" /> -->
</td>
</tr>
<!--Discount Value starts here /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-->
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px;"><asp:Label ID="lbl_discamt" runat="server" Text="Discount Amount:"></asp:Label> </td>
<td style="text-align: left; white-space: nowrap; height: 25px; background-color:white"><asp:TextBox ID="txtDiscountValue" Width="150px" runat="server" ReadOnly="true" BackColor="#F0F0F0" Text="" ></asp:TextBox>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px;"> </td>
<td style="text-align: left; white-space: nowrap; height: 25px;"> </td>
</tr>
<!--Discount Value ends here /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-->
<tr>
<td style="text-align: right; white-space: nowrap; height: 25px; vertical-align:top">
<asp:Label ID="lblTotal" runat="server" ForeColor="crimson" Font-Bold="true" Text="Total : $"></asp:Label></td>
<td style="text-align: left; white-space: nowrap; height: 25px;">
<!--location of Total field -->
<!--
<input type="text" name="Total" size="23" value="" style="background-color:#FFFFCC;font-weight:bold;color:#FF0000;" readonly="readonly" disabled="disabled"/>
-->
<asp:TextBox ID="txtTotal" runat="server" Width="100px" Enabled="false"></asp:TextBox>
<!--location of hdnTotal field -->
<asp:TextBox ID="hdnTotal" Width="150px" runat="server" ReadOnly="true" Visible="false" BorderColor="red" ></asp:TextBox>
</td>
<td style="text-align: left; white-space: nowrap; height: 25px; background-color:white"> </td> <td style="text-align: left; white-space: nowrap; height: 25px; background-color:white"> </td>
</tr>
</table>
<p></p>
<hr />
</AdditionalFormControls>
<RSVPResponseText>
<font face="Arial, Helvetica, sans-serif">
Thank you for registering! Your payment has been received. <br />
If you have questions please contact Gina Mitteco:<br />
(713) 993-4583<br />
<a href="mailto:gina.mitteco@h-gac.com">gina.mitteco@h-gac.com</a>.
<br /><br />
Please print this confirmation for your records.
</font>
</RSVPResponseText>
</HGACServerControls:RSVPForm>
hdnTotal.Value
 to get he same value assigned by JS in your page