Avatar of Codeaddict7423
Codeaddict7423
Flag for United States of America asked on

promo code to offer discount

Hello,
I have a user control built on Visual Studio 2005 C#. I am using javascript to calculate total cost of attending a conference or workshop.  I am attempting to have a promo code that can be verified against a database table, and if code verification is true, then offer a discount (percentage and/or hard dollar) from the total cost.

Any example providing a promo code verification yes/no that could be then applied to the total cost of conference/workshop would work.

ANY help would be greatly appreciated.
ASP.NETC#JavaScript

Avatar of undefined
Last Comment
Codeaddict7423

8/22/2022 - Mon
carlnorrbom

Hi,

Would need to understand a but more of the requirements. Are you looking to adding different promocodes which are valid for a certain period of time? Should they be general or personal? Should they be generated randomly or named? Anything else you can think of? Setting up db and doing verification against it is trivial, it's the business process and logic that presents the challenge in my opinion.

/Carl.
Codeaddict7423

ASKER
calnorrbom,
Thank you for the quick reply. First, i miscategorized my question. My development platfrm is Visual Studio 2005 using VB.NET 2.0 and a sql 2008 database.  I am creating a user control (*.ascx) to be imported into an *.aspx page so the entire transaction/cost calculation is handled within the control.
My logic follows:
I am creating a database table that will contain promotional codes that will be entered here at my agency.These codes will  be emailed to specific existing and prospective clients.  The codes are meant to offer a % discount and a hard-dollar discount. The table where the promo codes will  be stored has a "start date" and an "end date" and an "active" boolean column.
What I'm attempting to do is for us to enter these codes manually into the database table. Clients will be sent emails with instructions to use a specific "promo code" to get a discount on events/workshops/etc
After a certain date, the "promo code" will expire and will not discount the price of the conference/workshop./etc.  
I wouild like to handle the entire cost calculation on the asp side.
ANY help would be greatly appreciated.
Stephan

If I'm reading this right you want the following things:

- promotioncode validation on start-end date and isActive
- discount through % or Hard dollars

The above two items you want to do this through Javascript?

What I understand is dat you are using an user control within a page that does the calculation, and it is possible within the user control to use a promotion code.

Let me know if I understand this right so I could look for an answer.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Codeaddict7423

ASKER
stephanonline,
Thank you for the quick reply.
You have almost everything right.  
the promotioncode validation should check for start_date and end_date
There should be a check to see if the promo code is "active"
These items i want to handle through a vb.net sub not JavaScript.

--
Yes, the form and calculation is done on a user control (*.ascx) and then exported to a page (*.aspx)
I am attempting to handle the calculation to display the amount saved and the amount after the discount code is applied.

Below, please find my initial code attempts
-----------------
<%@ Control Language="VB" ClassName="RSVP_PedBike_Promo_Test01" %>

<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
           
            Dim txtPromoCode As TextBox
            Dim txtDiscount 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

            If txtPromoCode.Text.Length > 0 Then
                Dim Discount As Decimal = (totalBox * Integer.Parse(txtPromoCode.Text)) / 100
                sum = sum - Discount
                txtDiscount.Text = Discount.ToString
           
            End If
            Me.txtDiscount.Text = sum
       
       
       
            Me.hdnTotal.Text = sum.ToString("$0.00")
       
           
           
            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")
        ' Dim Attendee_FName As HiddenField
       
        'Request.Form("hdnTotal")
       
        'hdnTotal = RSVPForm1.FindControl("hdnTotal")
        'Attendee_FName = RSVPForm1.FindControl("Attendee_FName")

        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
       
        ' If Not (Attendee_FName Is Nothing) Then
        'Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "Attendee_FNameIdScript", "var Attendee_FNameId = '" + Attendee_FName.ClientID + "';", True)
        ' End If
       
       
       
       
    End Sub
       
    Private Sub TotalSum()
        Dim sum As Decimal = 0
        Dim txtPromoCode As New TextBox
        Dim txtDiscount As New TextBox
        Dim hdnTotal As HiddenField
       
        For Each row As DataGridViewRow In OrdersDetailsDataGridView.Rows
            row.Cells(5).Value = row.Cells(4).Value * row.Cells(3).Value
            sum += row.Cells(5).Value
 
        Next
       
        If txtPromoCode.text.length > 0 Then
            Dim Discount As Decimal = (sum * Integer.Parse(txtPromoCode.text)) / 100
            sum = sum - Discount
            txtDiscount.Text = Discount.ToString
           
        End If
        Me.txtDiscount.Text = sum
       
       
       
        Me.hdnTotal.Text = sum.ToString("$0.00")
       
     
    End Sub

   
   
   
   
   
</script>





<script language="JavaScript" type="text/javascript">

function RegTotal()
{
form = document.forms[0];
counter = 0;
form = document.forms[0];
            counter = 0;
            if ((form.txtNumberofTickets.value != "") || (form.txtNumberofTickets.value.length != 0)) {      
                  counter = form.txtNumberofTickets.value
            }
            
            form.Regcount.value = counter;
      
        form.Total.value = parseFloat(counter*25);
       
       


var obj = document.getElementById(hdnTotalId);

var obj1 = document.getElementById(Attendee_FNameId);

//obj.value below this line is what drives the second caculated total
obj.value = form.Total.value;
//obj1.value = form.Attendee_FName.value;


            var obj = document.getElementById("ctl00_ctl00_cphPage_cphContent_SpecialControl_RSVPForm1_hdnTotal");
        var obj1 = document.getElementById("ctl00_ctl00_cphPage_cphContent_SpecialControl_RSVPForm1_Attendee_FName");

            
            //obj.value = form.Total.value;
            //obj1.value = form.Attendee_FName.value;
            
            

var p = calcTotal(obj);
alert("Total Price = " + p);            
            

function calcTotal(obj) {
var discount = 0;
if (GOLD20) {discount = .20}
var price = obj.value;
var savings = obj.value * discount;
var total = price - savings;
return form.Total.value;

}
}

</script>








<div style="text-align:center"></div>
                <h3 style="text-align:center"> <br />
               
                  <span style="color:#66686d; font-size:20px; font-weight:bold">REGISTRATION FORM COUPON TEST FORM</span><br /> <br /><br />
</h3>
               

<HGACServerControls:RSVPForm ID="RSVPForm1" runat="server"  creditcardonly="true"  RSVPContactEmail="luis.hernandez@h-gac.com" RSVPFinancialCode="4000-108"  RSVPCode="General Law Cities Caucus" 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="510" 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="tbAttendee_FName" Text="First Name:"></asp:Label></td>
                   
                   <td style="text-align: left; white-space: nowrap; height: 25px; width:25%">
           
<asp:TextBox ID="tbAttendee_FName" runat="server"  Width="150px" MaxLength="150"  ></asp:TextBox >
                     
<asp:HiddenField ID="Attendee_FName"  runat="server" Visible="true"/>


                   
                 </td>
                    <td style="text-align: left; white-space: nowrap; height: 25px; width:5%">
                    &nbsp;<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="tbAttendee_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">
                    &nbsp;<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;"> &nbsp;</td>
          <td style="text-align: right; white-space: nowrap; height: 25px;"> &nbsp;</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;">&nbsp;<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;">
                 &nbsp;<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;">
                 &nbsp;<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;">
                &nbsp;<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;">
                &nbsp;<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;">
                &nbsp;<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;"> &nbsp;</td>
          <td style="text-align: right; white-space: nowrap; height: 25px;"> &nbsp;</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;">&nbsp;<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>
   <!--Discount Coupon call here -->
  <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="Label1" runat="server" Text="Number of Tickets:"></asp:Label>&nbsp;</td>
     
<td style="text-align: left; white-space: nowrap; height: 25px;">  
<input id="txtNumberofTickets" type="text" name="txtNumberofTickets" style="background-color:white; width:150px" onblur="RegTotal();" value="1" />
 
   
<asp:HiddenField ID="NumberofTickets"  runat="server" Visible="true"/>

 
 </td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td>
 
 <td style="text-align: left; white-space: nowrap; height: 25px;"><input type="text" name="Regcount" size="2" style="background-color:#CCCCCC" readonly="readonly" /> </td>      
 
  </tr>



 <!--Discount Coupon call here -->
 
 <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px; background-color:#ededed">
<asp:Label ID="Label2" runat="server" Text="Check Discount Code:"></asp:Label>&nbsp;</td>
     
<td style="text-align: left; white-space: nowrap; height: 25px;"><asp:TextBox ID="txtPromoCode" runat="server"></asp:TextBox></td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;
 
 <!--custom validator to check server side and client side -->
     <asp:CustomValidator ID=CustomValidator1 runat="server" ErrorMessage="CustomValidator"></asp:CustomValidator></td>
 
 <td style="text-align: left; white-space: nowrap; height: 25px;"><asp:ImageButton ID="btnGo" runat="server" AlternateText="Submit Promo Code" OnClick="btnGo_Click" />
 </td>      
 
  </tr>
 
 
 
 
 
 
 
 
  <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px;"><asp:Label ID="Label3" runat="server" Text="Amount of Discount:"></asp:Label>&nbsp;</td>
     
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="txtDiscount" runat="server"></asp:TextBox>&nbsp;</td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td>
 
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp; </td>      
 
  </tr>
 
 
 
 
 
 
 
    <tr>
              <td style="text-align: right; white-space: nowrap; height: 25px;">
              <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;">
             
                <input type="text" name="Total" size="23" value="" style="background-color:#FFFFBF;font-weight:bold;color:#FF0000;" readonly="readonly" disabled="disabled"/>  
 
  <!--location of hdnTotal field -->
 
               <asp:TextBox ID="hdnTotal"  Width="150px" runat="server" ReadOnly="true"  Visible="true" ></asp:TextBox>
             
</td>
              <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td>         <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td>      
                   
            </tr>
 
 
             </table>
             
              <p></p>
             <hr />
             
&#160;&#160;&#160;&#160;&#160;&#160;

             
             
 

           
</AdditionalFormControls>
        <RSVPResponseText>
            <font face="Arial, Helvetica, sans-serif">
            Thanks for registering! Payment of $25.00 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>
    &nbsp;
------------

Please help. I'm desperate for a working draft this afternoon.



Stephan

I cannot look through all the code... it's a bit too much haha...

What I can tell you to do is the following:

- CustomValidator to check if the discount code is valid within the requirements when submitted.
   - You can validate this through a linq query, sql query or Stored Procedure.
- When having the total cost, check what kind of discount it is...
 - For %:
TotalPrice / 100 * (% discount) = total discount
TotalPrice - total discount = totalprice with discount
 - For $ its simple:
TotalPrice - $ = Totalprice - discount

I would use the following promotion discount table

ID (identifier)
Code (code for validation)
Discount (value of discount)
DiscountType ($ or %)
StartDate
EndDate
IsActive
CreationDate
CreatedBy
Codeaddict7423

ASKER
stephanonline,
Sorry for the code dump.
Let's take these in stages....
CustomValidator (first time doing a CV) to check if  the promo code exists. SQL query is probably best for me at this stage. Discount is probably best as a hard dollar discount toget things working.
I'll create my promo table as suggested and will report progress/ask forhelp
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Codeaddict7423

ASKER
stephanonline,
I'm strugling with code issues and thought you might shed some light on what I'm doing.
My vb.net sub code follows:
-------
Private Sub CVPromoCode_ServerValidate_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CVPromoCode.ServerValidate
       
        Dim DSN_PROD As System.Data.SqlClient.SqlConnection
        DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode FROM tblPromoCodes WHERE ID = @ID"

        ' Initialize the sqlCommand with the new sql string.  
        Dim Command1 As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(query1, DSN_PROD)

        Dim PromoCode As Object
        'Create new parameters for the sqlCommand object and initialize them to the input values.    
        Command1.Parameters.AddWithValue("@PromoCode", PromoCode)

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        'get records column values
        DSN_PROD.Close()  
       
    End Sub
------
I'm getting a VS error indication at this line ( Command1.Parameters.AddWithValue("@PromoCode", PromoCode)) that says "value "promocode" is  used before it's been assigned a value"

 My custom vaildation control code follows:
-------
<!--Promo Coupon call starts here -->
 
 <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px; background-color:#ededed">
<asp:Label ID="Label2" runat="server" Text="Check Discount Code:"></asp:Label>&nbsp;</td>
     
<td style="text-align: left; white-space: nowrap; height: 25px;"><asp:TextBox ID="txtPromoCode" runat="server"></asp:TextBox></td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;
 
 <!--custom validator to check server side and client side -->
     <asp:CustomValidator ID="CVPromoCode" runat="server"  OnServerValidate="CVPromoCode_ServerValidate" Text="A username must be between 8 and 16 characters!" ErrorMessage="Invalid Promo Code" ControlToValidate="txtPromoCode"></asp:CustomValidator>
     
     </td>
 <td style="text-align: left; white-space: nowrap; height: 25px;">
 
<asp:Button ID="btnSubmit" Runat=server Text="GO" Font-Size="11px" ></asp:Button>
 </td>      
 
  </tr>
-----

Can you please review?
Stephan

You don't have a query that contains @PromoCode as Parameter. Try this instead:


Dim DSN_PROD As System.Data.SqlClient.SqlConnection
        DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode 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, DSN_PROD)

        Dim PromoCode As Object
        'Create new parameters for the sqlCommand object and initialize them to the input values.     
        Command1.Parameters.AddWithValue("@PromoCode", PromoCode)

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        DSN_PROD.Close()

Open in new window

Codeaddict7423

ASKER
stephanonline,
thanks for the quick reply.
i implemented your code and i see that VS is indicating hte following:
----------
 Private Sub CVPromoCode_ServerValidate_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls ServerValidateEventArgs) Handles CVPromoCode.ServerValidate
-------
the line "Handles CVPromoCode.ServerValidate" CVPromoCode has an error message as follows: "handles clause requires a "withEvents" variable defined in the containing type"


--------
line "Command1.Parameters.AddWithValue("@PromoCode", PromoCode)"
------
word  PromoCode" VS indicates that "PromoCode" is used before it has been assigned a value"
Can you please review?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Stephan

Dull of me, you are setting PromoCode as new object, and it is never assigned a value... You need to set the texbox value into the Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)
Codeaddict7423

ASKER
stephanonline,
thanks for the quick reply.
I'm getting the following error indication vrom VS
-----
Private Sub CVPromoCode_ServerValidate_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
       
       
       
        Dim DSN_PROD As System.Data.SqlClient.SqlConnection
        DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode 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, DSN_PROD)

        Dim PromoCode As Object
       
       
        'Create new parameters for the sqlCommand object and initialize them to the input values.  
        Dim txtPomoCode As TextBox
        Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        DSN_PROD.Close()
       
    End Sub
--------
the word "txtPromoCode" is underlined and VS says "txtPromoCode is not declared" ????
Codeaddict7423

ASKER
Stephanonline,
I caught my mistake. "txtPromoCode" was misspelled, however, now i see the familiar "txtPromoCode is used before it has been assigned a value" message. ???
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Stephan

txtPromoCode is an example for the textbox where you put in your promocode...

maybe you could zip it so I can take a look at it...

I will look into it tomorrow (around 8 hours, NL time :))
Stephan

I have got this and building properly:

-----------------
Code-behind
-----------------
Protected Sub ServerValidation(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
        Dim DSN_PROD As System.Data.SqlClient.SqlConnection
        DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode 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, DSN_PROD)
        Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)

        Dim PromoCode As Object
        'Create new parameters for the sqlCommand object and initialize them to the input values.    

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        DSN_PROD.Close()
    End Sub

---------------
Front page
---------------

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication2._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:textbox ID="txtPromoCode" runat="server"></asp:textbox>
    </div>
    </form>
</body>
</html>
Codeaddict7423

ASKER
stephanonline,
I have attached the entire user control to this post. Thank you for helping me.
<%@ Control Language="VB" ClassName="RSVP_PedBike_Promo_Test01" %>

<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
            ' Dim total As HiddenField
            
            ' Dim txtPromoCode As TextBox
            'Dim txtDiscountValue As HiddenField
            ' Dim hdnTotal 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

            'If txtPromoCode.Text.Length > 0 Then
               
            'Dim Discount As Decimal = (totalBox * Integer.Parse(txtPromoCode.Text)) / 100
                
            '  txtDiscountValue.Value = txtDiscountValue.ToString
            ' total = total.Value - txtDiscountValue.Value
                
            
            'End If
            'txtDiscountValue.Value = total.ToString("$0.00")
               
            'hdnTotal.Text = total.ToString("$0.00")

            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")
        ' Dim Attendee_FName As HiddenField
        
        'Request.Form("hdnTotal")
        
        'hdnTotal = RSVPForm1.FindControl("hdnTotal")
        'Attendee_FName = RSVPForm1.FindControl("Attendee_FName")

        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
        
        ' If Not (Attendee_FName Is Nothing) Then
        'Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "Attendee_FNameIdScript", "var Attendee_FNameId = '" + Attendee_FName.ClientID + "';", True)
        ' End If
                
    End Sub
        
    
     

    Private Sub CVPromoCode_ServerValidate_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
        
        
        
        Dim DSN_PROD As System.Data.SqlClient.SqlConnection
        ' DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode 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, DSN_PROD)

        Dim PromoCode As Object
       
       
        'Create new parameters for the sqlCommand object and initialize them to the input values.  
        Dim txtPromoCode As TextBox
        Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        DSN_PROD.Close()
        
    End Sub
    
    
    
    
</script>





<script language="JavaScript" type="text/javascript">

function RegTotal()
{
form = document.forms[0];
counter = 0;
form = document.forms[0];
		counter = 0;
		if ((form.txtNumberofTickets.value != "") || (form.txtNumberofTickets.value.length != 0)) {      
			counter = form.txtNumberofTickets.value
		}
		
		form.Regcount.value = counter;
	
        form.Total.value = parseFloat(counter*25);
        
       


var obj = document.getElementById(hdnTotalId);

var obj1 = document.getElementById(Attendee_FNameId);

//obj.value below this line is what drives the second caculated total 
obj.value = form.Total.value;
//obj1.value = form.Attendee_FName.value;


		var obj = document.getElementById("ctl00_ctl00_cphPage_cphContent_SpecialControl_RSVPForm1_hdnTotal");
        var obj1 = document.getElementById("ctl00_ctl00_cphPage_cphContent_SpecialControl_RSVPForm1_Attendee_FName");

		
		//obj.value = form.Total.value;
		//obj1.value = form.Attendee_FName.value;
		
		

var p = calcTotal(obj);
alert("Total Price = " + p);		
		

function calcTotal(obj) {
var discount = 0;
if (GOLD20) {discount = .20}
var price = obj.value;
var savings = obj.value * discount;
var total = price - savings;
return form.Total.value;

}
}

</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="true"  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="510" 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="tbAttendee_FName" Text="First Name:"></asp:Label></td>
                    
                   <td style="text-align: left; white-space: nowrap; height: 25px; width:25%">
           
<asp:TextBox ID="tbAttendee_FName" runat="server"  Width="150px" MaxLength="150"  ></asp:TextBox >
                     
<asp:HiddenField ID="Attendee_FName"  runat="server" Visible="true"/>


                   
                 </td>
                    <td style="text-align: left; white-space: nowrap; height: 25px; width:5%">
                    &nbsp;<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="tbAttendee_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">
                    &nbsp;<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;"> &nbsp;</td>
          <td style="text-align: right; white-space: nowrap; height: 25px;"> &nbsp;</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;">&nbsp;<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;">
                 &nbsp;<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;">
                 &nbsp;<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;">
                &nbsp;<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;">
                &nbsp;<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;">
                &nbsp;<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;"> &nbsp;</td>
          <td style="text-align: right; white-space: nowrap; height: 25px;"> &nbsp;</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;">&nbsp;<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>
  
   
   
  <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="Label1" runat="server" Text="Number of Tickets:"></asp:Label>&nbsp;</td> 
      
<td style="text-align: left; white-space: nowrap; height: 25px;">  
<input id="txtNumberofTickets" type="text" name="txtNumberofTickets" style="background-color:white; width:150px" onblur="RegTotal();" value="1" />
  
   
<asp:HiddenField ID="NumberofTickets"  runat="server" Visible="true"/>

 
 </td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td> 
  
 <td style="text-align: left; white-space: nowrap; height: 25px;"><input type="text" name="Regcount" size="2" style="background-color:#CCCCCC" readonly="readonly" /> </td>      
  
  </tr>



 <!--Promo Coupon call starts here --> 
 
 <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px; background-color:#ededed">
<asp:Label ID="Label2" runat="server" Text="Check Discount Code:"></asp:Label>&nbsp;</td> 
      
<td style="text-align: left; white-space: nowrap; height: 25px;"><asp:TextBox ID="txtPromoCode" runat="server"></asp:TextBox></td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;
 
 <!--custom validator to check server side and client side --> 
     <asp:CustomValidator ID="CVPromoCode" runat="server"  OnServerValidate="CVPromoCode_ServerValidate" Text="Enter Your Promo!" ErrorMessage="Invalid Promo Code" ControlToValidate="txtPromoCode"></asp:CustomValidator>
 
     </td> 
  
 <td style="text-align: left; white-space: nowrap; height: 25px;">
 
<asp:Button ID="btnSubmit" Runat=server Text="GO" Font-Size="11px" ></asp:Button>
 </td>      
  
  </tr>
 
 
 
  <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px;"><asp:Label ID="Label3" runat="server" Text="Amount of Discount:"></asp:Label>&nbsp;</td> 
      
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="txtDiscountValue" runat="server"></asp:TextBox>&nbsp;</td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td> 
  
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp; </td>      
  
  </tr>
  
  
  
  
  
  
  
    <tr>
              <td style="text-align: right; white-space: nowrap; height: 25px;">
              <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;">
              
                <input type="text" name="Total" size="23" value="" style="background-color:#FFFFBF;font-weight:bold;color:#FF0000;" readonly="readonly" disabled="disabled"/>  
 
  <!--location of hdnTotal field --> 
  
               <asp:TextBox ID="hdnTotal"  Width="150px" runat="server" ReadOnly="true"  Visible="true" ></asp:TextBox>
              
</td>
              <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td>         <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td>      
                    
            </tr>
  
  
             </table>
             
              <p></p>
             <hr />
             
&#160;&#160;&#160;&#160;&#160;&#160; 

             
             
 

            
</AdditionalFormControls>
        <RSVPResponseText>
            <font face="Arial, Helvetica, sans-serif">
            Thanks for registering! Payment of $25.00 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>
    &nbsp;

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Stephan

you don't need to define the textbox, it's already defined on your front side of the page:

you can remove this:
Dim txtPromoCode As TextBox

Like so:




<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication2._Default" %>
<script runat="server">

    Protected Sub ServerValidation(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
        Dim DSN_PROD As System.Data.SqlClient.SqlConnection
        DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode 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, DSN_PROD)
        Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)

        Dim PromoCode As Object
        'Create new parameters for the sqlCommand object and initialize them to the input values.    

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        DSN_PROD.Close()
    End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:textbox ID="txtPromoCode" runat="server"></asp:textbox>
    </div>
    </form>
</body>
</html>
Codeaddict7423

ASKER
stephanonline,
I copied your code behind and textbox call nad got this on run:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'txtPromoCode' is not declared.

Source Error:

 

Line 95:         ' Initialize the sqlCommand with the new sql string.  
Line 96:         Dim Command1 As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(query1, DSN_PROD)
Line 97:         Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)
Line 98:
Line 99:         Dim PromoCode As Object
 

Source File: Y:\default\main\www\WORKAREA\Common\htdocs\uc\RSVP\RSVP_PedBike_Promo_Test01.ascx    Line: 97


Codeaddict7423

ASKER
stephanonline,
Thank yoiu for staying with me for just a little while. I' m getting an error message from VS at line
-----
 Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)
-----
I'm getting a "txtPromoCode" is not declared..... ???
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Stephan

"txtPromoCode" is not declared....

You are probably not using the code behind of the user control, but putting the code on thesame page.

Try using the code-behind from now on because this is easier access and les disturbing.
Codeaddict7423

ASKER
stephanonline,
You're right. i was planning to have everything on one page but i opened up a code behind page and it looks like this:
--------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class uc_RSVP_PROMO_RSVP_PedBike_Promo_Test01 : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
}

-------
how do i declate "txtPromoCode" in this codebehind?
Stephan

When you create a new UserControl that contains an code-behind, starting from 2.0 the control will be automaticly registered in the generated.cs file. So you don't need to define it from the code-behind, it's already there if you have added into the front file.

Tip: Intellisense is your friend.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Codeaddict7423

ASKER
stephanonline,
in my *.ascx file, i have the following call:
------

    Protected Sub ServerValidation(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
        Dim DSN_PROD As System.Data.SqlClient.SqlConnection
        DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode 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, DSN_PROD)
        'Dim txtPromoCode As TextBox
       
        Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)

        Dim PromoCode As Object
        'Create new parameters for the sqlCommand object and initialize them to the input values.    

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        DSN_PROD.Close()
    End Sub
----
again, the word "txtPromoCode.Text" is highlighted indicating the i need to declare it.
My codebehind is as follows:
----
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class uc_RSVP_PROMO_RSVP_PedBike_Promo_Test01 : System.Web.UI.UserControl
{
    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DSN_PROD"].ToString());


    protected void Page_Load(object sender, EventArgs e)
    {
       
    }

}
----
my call to this sub comes from my code as follows:
---
<!--Promo Coupon call starts here -->
 
 <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px; background-color:#ededed">
<asp:Label ID="Label2" runat="server" Text="Check Discount Code:"></asp:Label>&nbsp;</td>
     
<td style="text-align: left; white-space: nowrap; height: 25px;">
 <asp:textbox ID="txtPromoCode" runat="server"></asp:textbox></td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;
 
 <!--custom validator to check server side and client side -->
     <asp:CustomValidator ID="CVPromoCode" runat="server"  OnServerValidate="CVPromoCode_ServerValidate" Text="Enter Your Promo!" ErrorMessage="Invalid Promo Code" ControlToValidate="txtPromoCode"></asp:CustomValidator>
 
     </td>
 
 <td style="text-align: left; white-space: nowrap; height: 25px;">
 
<asp:Button ID="btnSubmit" Runat=server Text="GO" Font-Size="11px" ></asp:Button>
 </td>      
 
  </tr>
------

Please help me get this working. i am trying to  get the custom validator to check the data table tblPromoCodes to see if a code is valid, then apply a hard-dollar discount to a ticket price.

I am desperate for a solution  here...
Stephan

Could you post the entire app in a zip or something... maybe on a separate url so I can download it. I don't see where it's going wrong.
Codeaddict7423

ASKER
stephanonline,
Attached, please find my *.ascx code. I am importing this *.ascx user control into a *.aspx page.
Please review
When i import this control into my *.aspx page, i get the following compilation error:
-------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'txtPromoCode' is not declared.

Source Error:

 

Line 97:         'Dim txtPromoCode As TextBox
Line 98:        
Line 99:         Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)
Line 100:
Line 101:        Dim PromoCode As Object
Source File: Y:\default\main\www\WORKAREA\Common\htdocs\uc\RSVP\RSVP_PedBike_Promo_Test01.ascx    Line: 99
-------


<%@ Control Language="VB" ClassName="RSVP_PedBike_Promo_Test01" %>

<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
            ' Dim total As HiddenField
            
            ' Dim txtPromoCode As TextBox
            'Dim txtDiscountValue As HiddenField
            ' Dim hdnTotal 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

            'If txtPromoCode.Text.Length > 0 Then
               
            'Dim Discount As Decimal = (totalBox * Integer.Parse(txtPromoCode.Text)) / 100
                
            '  txtDiscountValue.Value = txtDiscountValue.ToString
            ' total = total.Value - txtDiscountValue.Value
                
            
            'End If
            'txtDiscountValue.Value = total.ToString("$0.00")
               
            'hdnTotal.Text = total.ToString("$0.00")

            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")
        ' Dim Attendee_FName As HiddenField
        
        'Request.Form("hdnTotal")
        
        'hdnTotal = RSVPForm1.FindControl("hdnTotal")
        'Attendee_FName = RSVPForm1.FindControl("Attendee_FName")

        '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
        
        ' If Not (Attendee_FName Is Nothing) Then
        'Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "Attendee_FNameIdScript", "var Attendee_FNameId = '" + Attendee_FName.ClientID + "';", True)
        ' End If
                
    End Sub
        
    
     

    Protected Sub ServerValidation(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
        Dim DSN_PROD As System.Data.SqlClient.SqlConnection
        DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode 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, DSN_PROD)
        'Dim txtPromoCode As TextBox
        
        Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)

        Dim PromoCode As Object
        'Create new parameters for the sqlCommand object and initialize them to the input values.     

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        DSN_PROD.Close()
    End Sub



    
    
    
</script>





<script language="JavaScript" type="text/javascript">

function RegTotal()
{
form = document.forms[0];
counter = 0;
form = document.forms[0];
		counter = 0;
		if ((form.txtNumberofTickets.value != "") || (form.txtNumberofTickets.value.length != 0)) {      
			counter = form.txtNumberofTickets.value
		}
		
		form.Regcount.value = counter;
	
        form.Total.value = parseFloat(counter*25);
        
       


var obj = document.getElementById(hdnTotalId);

var obj1 = document.getElementById(Attendee_FNameId);

//obj.value below this line is what drives the second caculated total 
obj.value = form.Total.value;
//obj1.value = form.Attendee_FName.value;


		var obj = document.getElementById("ctl00_ctl00_cphPage_cphContent_SpecialControl_RSVPForm1_hdnTotal");
        var obj1 = document.getElementById("ctl00_ctl00_cphPage_cphContent_SpecialControl_RSVPForm1_Attendee_FName");

		
		//obj.value = form.Total.value;
		//obj1.value = form.Attendee_FName.value;
		
		

var p = calcTotal(obj);
alert("Total Price = " + p);		
		

function calcTotal(obj) {
var discount = 0;
if (GOLD20) {discount = .20}
var price = obj.value;
var savings = obj.value * discount;
var total = price - savings;
return form.Total.value;

}
}

</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="true"  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="510" 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="tbAttendee_FName" Text="First Name:"></asp:Label></td>
                    
                   <td style="text-align: left; white-space: nowrap; height: 25px; width:25%">
           
<asp:TextBox ID="tbAttendee_FName" runat="server"  Width="150px" MaxLength="150"  ></asp:TextBox >
                     
<asp:HiddenField ID="Attendee_FName"  runat="server" Visible="true"/>


                   
                 </td>
                    <td style="text-align: left; white-space: nowrap; height: 25px; width:5%">
                    &nbsp;<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="tbAttendee_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">
                    &nbsp;<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;"> &nbsp;</td>
          <td style="text-align: right; white-space: nowrap; height: 25px;"> &nbsp;</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;">&nbsp;<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;">
                 &nbsp;<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;">
                 &nbsp;<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;">
                &nbsp;<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;">
                &nbsp;<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;">
                &nbsp;<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;"> &nbsp;</td>
          <td style="text-align: right; white-space: nowrap; height: 25px;"> &nbsp;</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;">&nbsp;<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>
  
   
   
  <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px;">
<asp:Label ID="Label1" runat="server" Text="Number of Tickets:"></asp:Label>&nbsp;</td> 
      
<td style="text-align: left; white-space: nowrap; height: 25px;">  
<input id="txtNumberofTickets" type="text" name="txtNumberofTickets" style="background-color:white; width:150px" onblur="RegTotal();" value="1" />
  
   
<asp:HiddenField ID="NumberofTickets"  runat="server" Visible="true"/>

 
 </td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td> 
  
 <td style="text-align: left; white-space: nowrap; height: 25px;"><input type="text" name="Regcount" size="2" style="background-color:#CCCCCC" readonly="readonly" /> </td>      
  
  </tr>



 <!--Promo Coupon call starts here --> 
 
 <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px; background-color:#ededed">
<asp:Label ID="Label2" runat="server" Text="Check Discount Code:"></asp:Label>&nbsp;</td> 
      
<td style="text-align: left; white-space: nowrap; height: 25px;">
 <asp:textbox ID="txtPromoCode" runat="server"></asp:textbox></td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;
 
 <!--custom validator to check server side and client side --> 
     <asp:CustomValidator ID="CVPromoCode" runat="server"  OnServerValidate="CVPromoCode_ServerValidate" Text="Enter Your Promo!" ErrorMessage="Invalid Promo Code" ControlToValidate="txtPromoCode"></asp:CustomValidator>
 
     </td> 
  
 <td style="text-align: left; white-space: nowrap; height: 25px;">
 
<asp:Button ID="btnSubmit" Runat=server Text="GO" Font-Size="11px" ></asp:Button>
 </td>      
  
  </tr>
 
 
 
  <tr>
  <td style="text-align: right; white-space: nowrap; height: 25px;"><asp:Label ID="Label3" runat="server" Text="Amount of Discount:"></asp:Label>&nbsp;</td> 
      
<td style="text-align: left; white-space: nowrap; height: 25px;">
<asp:TextBox ID="txtDiscountValue" runat="server"></asp:TextBox>&nbsp;</td>    
   
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td> 
  
 <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp; </td>      
  
  </tr>
  
  
  
  
  
  
  
    <tr>
              <td style="text-align: right; white-space: nowrap; height: 25px;">
              <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;">
              
                <input type="text" name="Total" size="23" value="" style="background-color:#FFFFBF;font-weight:bold;color:#FF0000;" readonly="readonly" disabled="disabled"/>  
 
  <!--location of hdnTotal field --> 
  
               <asp:TextBox ID="hdnTotal"  Width="150px" runat="server" ReadOnly="true"  Visible="true" ></asp:TextBox>
              
</td>
              <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td>         <td style="text-align: left; white-space: nowrap; height: 25px;">&nbsp;</td>      
                    
            </tr>
  
  
             </table>
             
              <p></p>
             <hr />
             
&#160;&#160;&#160;&#160;&#160;&#160; 

             
             
 

            
</AdditionalFormControls>
        <RSVPResponseText>
            <font face="Arial, Helvetica, sans-serif">
            Thanks for registering! Payment of $25.00 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>
    &nbsp;

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Stephan

I mean the entire project so I can open it in VS, because I cannot reproduce your problem.
Codeaddict7423

ASKER
stephanonline,
please let me explain. I'm  using a content management system that produces *.aspx pages. into these *.aspx pages, i import user controls to handle registration forms. I am working on one of these user controls that is imported into the content management system to generate the *.aspx page along with the user control.

the error i am getting reflects line 99 in the code that states:
--
 Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)
----
txtPromoCode.text
Visual Studio indicated that "txtPromoCode.Text" is not declared.

how can i get edit the sub " Protected Sub ServerValidation(ByVal sender As Object, ByVal args As ServerValidateEventArgs)" so that it checks for the promo codes stored in datatable "tblPromoCodes" ?


ASKER CERTIFIED SOLUTION
Stephan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Codeaddict7423

ASKER
stephanonline,
When i highlight the "txtPromoCode.Text", intellisense pops up a window stating " Name 'txtPromoCode' is not declared"

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Codeaddict7423

ASKER
stephanonline,
I edite the sub as folllows:
-------
 Protected Sub ServerValidation(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
        Dim DSN_PROD As System.Data.SqlClient.SqlConnection
        DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode 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, DSN_PROD)
        Dim txtPromoCode As New TextBox
       
        Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)

        Dim PromoCode As Object
        'Create new parameters for the sqlCommand object and initialize them to the input values.    

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        DSN_PROD.Close()
    End Sub
-------

I made this change
-------
   Dim txtPromoCode As New TextBox
-----
I then ran the code and got this:
-------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30456: 'CVPromoCode_ServerValidate' is not a member of 'ASP.RSVP_PedBike_Promo_Test01'.

Source Error:
Line 380:
Line 381: <!--custom validator to check server side and client side -->
Line 382:     <asp:CustomValidator ID="CVPromoCode" runat="server"  OnServerValidate="CVPromoCode_ServerValidate" Text="Enter Your Promo!" ErrorMessage="Invalid Promo Code" ControlToValidate="txtPromoCode"></asp:CustomValidator>
Line 383:
Line 384:     </td>
 
Source File: Y:\default\main\www\WORKAREA\Common\htdocs\uc\RSVP\RSVP_PedBike_Promo_Test01.ascx    Line: 382
--------

what am I doing wrong?
Codeaddict7423

ASKER
stephanonline,
OK, I got this to display. I made the change to the name of the sub as follows:
-------
Protected Sub CVPromoCode_ServerValidate(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
        Dim DSN_PROD As System.Data.SqlClient.SqlConnection
        DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode 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, DSN_PROD)
        Dim txtPromoCode As New TextBox
       
        Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)

        Dim PromoCode As Object
        'Create new parameters for the sqlCommand object and initialize them to the input values.    

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        DSN_PROD.Close()
    End Sub
------
now the page displays but i attemp to run the validation routine, i get this:
-----
Format of the initialization string does not conform to specification starting at index 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Source Error:


Line 90:     Protected Sub CVPromoCode_ServerValidate(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
Line 91:         Dim DSN_PROD As System.Data.SqlClient.SqlConnection
Line 92:         DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection")
Line 93:         DSN_PROD.Open()
Line 94:         ' Build a sql statement string    
-----------

line 92:    DSN_PROD = New System.Data.SqlClient.SqlConnection("myconnection") is highlighed in red


Codeaddict7423

ASKER
stephanonline,
I modified my sub as follows:
--------
Protected Sub CVPromoCode_ServerValidate(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
       
        Dim DSN_PROD As System.Data.SqlClient.SqlConnection
     
        DSN_PROD = New System.Data.SqlClient.SqlConnection("Conn")
           
        DSN_PROD.Open()
        ' Build a sql statement string    
        Dim query1 As String = "Select PromoCode 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, DSN_PROD)
        Dim txtPromoCode As New TextBox
       
        Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)

        Dim PromoCode As Object
        'Create new parameters for the sqlCommand object and initialize them to the input values.    

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        DSN_PROD.Close()
    End Sub
------
The compilation error msg i get now is like this:
----
Format of the initialization string does not conform to specification starting at index 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Source Error:
Line 93:      
Line 94:        
Line 95:         DSN_PROD = New System.Data.SqlClient.SqlConnection("Conn")
Line 96:      
Line 97:        
 ----------

Line 95  is highlighted.......
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Codeaddict7423

ASKER
stephanonline,
Any thoughts on my last post? I seem to have trouble with the connection string inside the sub called "Protected Sub CVPromoCode_ServerValidate(ByVal sender As Object, ByVal args As ServerValidateEventArgs)"

ANY help would be greatly appreciated.
Codeaddict7423

ASKER
stephanonline,
I solved the database connection string problem. Below, please find my sub code:
--------
Protected Sub CVPromoCode_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
       
        ' 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 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)
       
        Dim txtPromoCode As New TextBox
       
        Command1.Parameters.AddWithValue("@PromoCode", txtPromoCode.Text)

        Dim PromoCode As Object
        'Create new parameters for the sqlCommand object and initialize them to the input values.    

        'Execute the command
        PromoCode = Command1.ExecuteScalar

        'Dim strValue

        ' strValue = UCase(PromoCode.Value)
        ' If InStr(strValue, "Promo Code Accepted") > 0 Then
        'PromoCode.IsValid = True
        '  Else
        ' PromoCode.IsValid = False
        ' End If

       
       
        myConnection.Close()
    End Sub
------

What I'm attempting to do now is to edit this code to check whether a promo code is vaild (and display a msg that says "code accepted") or code is invalid (and display a msg that says "code expired")

After that, my goal is to calculate a discount from an event ticket price, show the discount and discounted total.

ANYhelp you could provide would be greatly appreciated.