Solved

Sending a email when checkbox is clicked.

Posted on 2004-09-06
3
314 Views
Last Modified: 2008-03-10
I have a register page, on this page is a at the bottom is a check box, as you can see from me code below.

I also want if the user click the ‘call me back’ check box to sent a email to a address aswell.

Can this be done in asp.net if so how, in my code

My code is below so you can see what I mean, and what I have so far.

thank you in advance,



_____________




<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">
            
             Sub Submit_Click(Sender as Object, e as EventArgs)
             Dim cnn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.mappath("cl.mdb"))
        Dim cmd As New OleDb.OleDbCommand
          Page.Validate
If Page.IsValid Then
        cmd.CommandText = "INSERT INTO members (title, first_name, last_name, company_name, house_number_name, street, address1, address2, town, postcode, telephone, fax, email, pass, web_address, sector, no_employees, hear_about_us, callback, keep_todate) VALUES ('" & title.Value  & "', '" & first_name.Value  & "', '" & last_name.Value  & "', '" & company_name.Value  & "', '" & house_number_name.Value  & "', '" & street.Value  & "', '" & address1.Value  & "', '" & address2.Value  & "', '" & town.Value  & "', '" & postcode.Value  & "', '" & telephone.Value  & "', '" & fax.Value  & "', '" & email.Value  & "', '" & pass.Value  & "', '" & web_address.Value  & "', '" & sector.Value  & "', '" & no_employees.Value  & "', '" & hear_about_us.Value  & "', '" & callback.checked & "', '" & keep_todate.checked & "')"

        cmd.Connection = cnn

        cnn.Open()
        cmd.ExecuteNonQuery()
        cnn.Close()

        cmd.Dispose()
        cnn.Dispose()
         
          Response.Redirect("thankyou.html")
Else
'Do Whatever
End IF
     
     end sub

      
      </script>
      
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/mainTemplate.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="quotes.js"></SCRIPT>

<script>
function quotePrint()
{
var index = parseInt(Math.random()*Quotes.length)

return(Quotes[index])
}

</script>
      <!-- InstanceBeginEditable name="doctitle" -->
      <title>Register Page</title>
      <!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <!-- InstanceBeginEditable name="head" -->
      <style type="text/css">
<!--
.style6 {font-size: 9px}
-->
    </style>
      <!-- InstanceEndEditable -->
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {
      font-size: 16px;
      font-weight: bold;
}
.style4 {font-size: 14px}
.style5 {font-size: 14px; font-weight: bold; }
-->
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
      <tr>
            <td style="width: 5%; background: #EEE; border-right: 1px solid #AAA;">&nbsp;</td>
            <td>
            <div class="londonLandscape">
                  <a href="index.html" target="_self"><img src="images/logo.gif" alt="Connecting London Logo" border="0" align="left" style="margin-right: 10px; "></a>
                  <img src="images/londonpic.jpg" alt="Connecting London Logo" align="right">
              <div style="padding-top: 15px; "><br />
                  <span class="textSize style1"><span class="textSize style4">Information - Communications - Technology</span></span><span class="style5"></span><span class="style1"><br />
               </span>              <span class="blueText">We support you...</span></div>
              <span class="blueText">not just your systems!</span></div>
            </div>
            <div id="topmenu1">
                <div style="float:right; "><a href="aboutus.html" target="_self">about us</a> | <a href="contactus.html" target="_self">contact us</a> | <a href="legal.html"> legal</a> | <a href="careers.html" target="_self">careers</a> | <a href="sitemap.html" target="_self">sitemap</a></div>
                         <!-- InstanceBeginEditable name="stat" -->home&gt;register<!-- InstanceEndEditable -->
            </div>
            <div style="clear: both; margin-top: 20px;">
                  <div class="box3">
                  <div class="specialOfferBox">
                  <div class="smallTitle" style="color:#FF0000; font-size: 12px;">Special Offer This Month</div>
            </div>
            <div class="graybox">
                  <center><b>
                  <p>EMAIL PROTECTION AGENCY (EPA) SPAM PROTECTION FOR BUSINESS:</p>
                  <p class="FreeTrial"> FREE 15-DAY TRIAL</p>
                  <p>EPA Spam Potection is <br>
                    available to registered <br>
                    Connecting London <br>
                members FREE for 15 days.</p>
                  </b>
                    <p>members click here <a href="membercheck.aspx">click here</a>.
                  <p class="textSize">If you are not a Connecting London member, and would like to apply for membership please register <span class="redlink"><a href="register.aspx">click here
                  </a></span><br>
                  <br>There's no charge for joining, and you do not have to be an existing client.</p>
                  </center>
            </div>
            <div class="smallTitle">Our business partners</div>
                  <div class="graybox" align="center">
                    <img src="images/logos.jpg" alt="logos">
            </div>
      </div>
<div class="box1">
            <div id="nav" style="padding-bottom: 30px; ">
                  <ul class="level1">
                  <li><a href="index.html"><strong>Home</strong></a></li>
                  <li><a href="private_clients .html"><strong>Private Client Computing</strong></a></li>
                  <li class="submenu"><a href="corporate_client_computing.html"><strong>Corporate Client Computing </strong></a>
                   <ul class="level2">
                   <li><a href="corporate_client_consultancy.html">Consultancy</a></li>
                  <li><a href="/">Networks</a></li>
                  <li><a href="/">Computer Services</a></li>
                  <li><a href="communications_services.html">Communications Services </a></li>
                  <li><a href="internet_services.html">Internet Services</a></li>
                  <li><a href="training_and_familiarisation.html">Training</a></li>
                  <li><a href="service_and_maintenance.html">Service and Maintenance</a></li>
                  <li><a href="/">Financing</a></li>
             </ul>
            </li>
            <li><a href="computer_systems_maintenance_service_and_support.html"><strong>Service & Maintenance</strong></a></li>
            <li><a href="case_histories.html"><strong>Case Histories</strong></a></li>
              <li><a href="customer_charter.html"><strong>Customer Charter</strong></a></li>
        </ul>
</div>
<div class="smallTitle" align="right">Members Email Login</div>
      <div class="graybox"><form method="post" action="membercheck.aspx">
      <center>
      
      


      User Name
      <input name="username" type="text">
      Password
      <input name="password" type="password">
      <br>
      <div align="right">
      <input name="Login" type="submit" value="Login">
      
      </div>
      </center></form>
      If you are a registered member and want to access the members area please <a href="membercheck.aspx">click here</a>      </div>
      <div class="smallTitle" align="right">What our clients say about us</div>
      <div class="graybox">
            <script>document.write(quotePrint())</script>
      </div>
</div>
      <div class="box2">
            <!-- InstanceBeginEditable name="content" -->
            <div class="graybar"><img src="images/headings/register.gif" alt="corporate client image"></div>
            <p>Welcome to connecting London's registration page. Please fill in the entire form below to register with us. All fields in <b>bold</b> are mandatory.</p>  
            
            <form runat="server">
<table width="auto"  border="0" align="left" cellpadding="5" cellspacing="0">
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>Title:</b></div></td>
    <td bgcolor="#F7F7F7"><div align="left">
      <input name="text" type="text" id="title" value="" runat="server">
    </div></td>
    <td><div align="left">
      <asp:RequiredFieldValidator runat=server
            ControlToValidate=title
            ErrorMessage=""> * </asp:RequiredFieldValidator>
    </div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>First Name:</b></div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="first_name" value="" runat="server">
          </div></td>
    <td><div align="left">
      <asp:RequiredFieldValidator runat=server
            ControlToValidate=first_name
            ErrorMessage=""> * </asp:RequiredFieldValidator>
    </div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>Last Name:</b></div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="last_name" value="" runat="server">
          </div></td>
    <td><div align="left">
      <asp:RequiredFieldValidator runat=server
            ControlToValidate=last_name
            ErrorMessage=""> * </asp:RequiredFieldValidator>
       </div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right">Company Name:</div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="company_name" value="" runat="server">
          </div></td>
    <td>
       <div align="left"></div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>Address Number/Name:</b></div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="house_number_name" value="" runat="server">
          </div></td>
    <td><div align="left">
      <asp:RequiredFieldValidator runat=server
            ControlToValidate=house_number_name
            ErrorMessage=""> * </asp:RequiredFieldValidator>
        </div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>Street</b></div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="street" value="" runat="server">
          </div></td>
    <td><div align="left">
      <asp:RequiredFieldValidator runat=server
            ControlToValidate=street
            ErrorMessage=""> * </asp:RequiredFieldValidator>
        </div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>Address 1:</b></div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="address1" value="" runat="server">
          </div></td>
    <td><div align="left">
      <asp:RequiredFieldValidator runat=server
            ControlToValidate=address1
            ErrorMessage=""> * </asp:RequiredFieldValidator>
        </div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right">Address 2:</div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="address2" value="" runat="server">
          </div></td>
    <td>
        <div align="left"></div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>Town:</b></div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="town" value="" runat="server">
          </div></td>
    <td><div align="left">
      <asp:RequiredFieldValidator runat=server
            ControlToValidate=town
            ErrorMessage=""> * </asp:RequiredFieldValidator>
        </div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>PostCode:</b></div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="postcode" value="" runat="server">
          </div></td>
    <td><div align="left">
      <asp:RequiredFieldValidator runat=server
            ControlToValidate=postcode
            ErrorMessage=""> * </asp:RequiredFieldValidator>
        </div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>Telephone:</b></div></td>
    <td bgcolor="#F7F7F7">  
        <div align="left">
          <input type="text" ID="telephone" value="" runat="server">
          </div></td>
            
    <td><div align="left">
      <asp:RequiredFieldValidator runat=server
            ControlToValidate=telephone
            ErrorMessage=""> * </asp:RequiredFieldValidator>
                    
                  <asp:RegularExpressionValidator runat=server display=dynamic
            ControlToValidate="telephone"
            ErrorMessage="Tel must be 8 12 nonblank characters."
            ValidationExpression="[^\s]{4,12}"/>            
 

     </div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right">Fax Number:</div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="fax" value="" runat="server">
          </div></td>
    <td>
       <div align="left"></div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>Email Address</b></div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="text" ID="email" value="" runat="server">
          </div></td>
    <td>
       <div align="left"><asp:RegularExpressionValidator id="valRegEx" runat="server"
    ControlToValidate="email"
    ValidationExpression=".*@.*\..*"
    ErrorMessage="Your entry is not a valid e-mail address."
    display="dynamic">*
</asp:RegularExpressionValidator></div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right"><b>Password:</b></div></td>
    <td bgcolor="#F7F7F7">
        <div align="left">
          <input type="password" ID="pass" value="" runat="server">
          </div></td>
    <td><div align="left">
      <asp:RequiredFieldValidator runat=server
            ControlToValidate=pass
            ErrorMessage=""> * </asp:RequiredFieldValidator>
            
                  
                              
       
     </div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right">Re-type Password</div></td>
    <td bgcolor="#F7F7F7"><div align="left">
      <input type="password" ID="passcheck" value="" runat="server">
    </div></td>
    <td><div align="left">
      <asp:CompareValidator runat=server
            controltovalidate=pass
            controltocompare=passcheck
            errormessage="Passwords do not match." />    
</div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right">Web Address:</div></td>
    <td bgcolor="#F7F7F7">  
        <div align="left">
          <input type="text" ID="web_address" value="" runat="server">
          </div></td>
    <td>
      <div align="left"></div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right">Business Sector:</div></td>
    <td bgcolor="#F7F7F7">      
        <div align="left">
            <select id="sector" runat="server">
                                <option value="None Selected">Select</option>
                      <option value="Automotive">Automotive</option>
                      <option value="Computers">Computers</option>  
                      <option value="Construction">Construction</option>
                              <option value="Consumer Goods">Consumer Goods</option>
                              <option value="Education">Education</option>
                              <option value="Electronics">Electronics</option>
                              <option value="Entertainment">Entertainment</option>
                              <option value="Financial Institution">Financial Institution</option>
                              <option value="Insurance">/Insurance</option>
                              <option value="Other">/Other</option>
                              <option value="Government">Government</option>
                              <option value="Military">Military</option>
                              <option value="Public Sector">Public Sector</option>
                              <option value="Hospitality">Hospitality</option>
                              <option value="Recreation">Recreation</option>
                              <option value="Leisure Industry">Leisure Industry</option>
                              <option value="Manugacturer">Manugacturer</option>
                              <option value="Media">Media</option>
                              <option value="Medical">Medical</option>
                              <option value="Health Services">Health Services</option>
                              <option value="Pharmaceuticals">Pharmaceuticals</option>
                              <option value="Professional Services">Professional Services</option>
                              <option value="Publishers">Publishers</option>
                              <option value="Retail">Retail</option>
                              <option value="Telecommunications">Telecommunications</option>
                              <option value="Travel">Travel</option>
                              <option value="Transportation">Computers</option>
            </select>
          </div></td>
    <td>
      <div align="left"></div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right">No. Employees:</div></td>
    <td bgcolor="#F7F7F7">    
        <div align="left">
            <select id="no_employees" runat="server">
                                <option value="None Selected">Select</option>
                      <option>1-10</option>
                      <option>11-25</option>  
                      <option>26-50</option>  
                      <option>50+</option>  
            </select>
          </div></td>
    <td>
      <div align="left"></div></td>
  </tr>
  <tr>
    <td bgcolor="#F7F7F7"><div align="right">How did you hear about us?</div></td>
    <td bgcolor="#F7F7F7">        
        <div align="left">
            <select id="hear_about_us" runat="server">
                                <option value="None Selected">Select</option>
                      <option>Colour Pages</option>
                      <option>Direct Mail</option>  
                      <option>Internet</option>  
                      <option>Referral</option>  
                      <option>Yellow Pages</option>  
                      <option>Yell.com</option>
                      <option>Other</option>  
            </select>
          </div></td>
    <td>
      <div align="left"></div></td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#F7F7F7">Please call me to set-up the EPA (Email Protection Agency) FREE 15 day trial.
            <asp:CheckBox ID="callback" runat="server" Checked="true" />
        </td>
    <td></td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#F7F7F7">
    <td></td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#F7F7F7">Tick here to keep you up to date with the latest IT devleopments. Get more out of your existing technologies, find out about essential resources, new technology guides & time saving hints to help you get more done, cost effectively. Please untick the box if you do not want to subscribe.
<asp:CheckBox ID="keep_todate" runat="server" Checked="true" /></td>
    <td></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td colspan="3"><div align="center">
            <input type="submit" OnServerClick="Submit_Click" value="Submit" runat="server">
            <span class="style6">only submit once
            </span> </div></td>
    </tr>
</table>

</form>

            <!-- InstanceEndEditable --></div>
</div>
      <div class="box4">
              For more information call:<br>
            <b>Gary Howells on 020 7591 5455 or Robert Saleh on 020 7591 5454<br></b>
             or <a href="mailto:email sales@connectinglondon.com ">email sales@connectinglondon.com </a></div>
      </td>
            <td style="width: 5%; background: #EEE; border-left: 1px solid #AAA;">&nbsp;</td>
      </tr>
</table>
</body>
<!-- InstanceEnd --></html>

0
Comment
Question by:pigmentarts
  • 2
3 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11990196
What is your exact problem ?  Sending the mail ? or checking the CheckBox status ?

-Baan
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11990518
Private Sub Callback_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Callback.CheckedChanged
try
Dim objEmailMessage As System.Web.Mail.MailMessage
Dim objSMTPServer As System.Web.Mail.SmtpMail
objSMTPServer.SmtpServer = "mycomputername"
objEmailMessage = New System.Web.Mail.MailMessage
With objEmailMessage
.To = "destinationemail@address.com"
.From = txtFrom.Text
.Subject = "Great Job!"
.Body = "Want all my money?"
.BodyFormat = MailFormat.Html
End With
objSMTPServer.Send(objEmailMessage)
catch exc as exception
response.write(exc.innerexception.innerexception.message)
end try
End Sub

Regards,

Aeros
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 500 total points
ID: 11991173
the above will send email when the check box is checked if you wanted to wait until the submit button to check and see then whether or not to send it would be something like this:


<script language="VB" runat="server">
         
             Sub Submit_Click(Sender as Object, e as EventArgs)
             Dim cnn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.mappath("cl.mdb"))
        Dim cmd As New OleDb.OleDbCommand
          Page.Validate
If Page.IsValid Then
        cmd.CommandText = "INSERT INTO members (title, first_name, last_name, company_name, house_number_name, street, address1, address2, town, postcode, telephone, fax, email, pass, web_address, sector, no_employees, hear_about_us, callback, keep_todate) VALUES ('" & title.Value  & "', '" & first_name.Value  & "', '" & last_name.Value  & "', '" & company_name.Value  & "', '" & house_number_name.Value  & "', '" & street.Value  & "', '" & address1.Value  & "', '" & address2.Value  & "', '" & town.Value  & "', '" & postcode.Value  & "', '" & telephone.Value  & "', '" & fax.Value  & "', '" & email.Value  & "', '" & pass.Value  & "', '" & web_address.Value  & "', '" & sector.Value  & "', '" & no_employees.Value  & "', '" & hear_about_us.Value  & "', '" & callback.checked & "', '" & keep_todate.checked & "')"

        cmd.Connection = cnn

        cnn.Open()
        cmd.ExecuteNonQuery()
        cnn.Close()

        cmd.Dispose()
        cnn.Dispose()
          If Me.Callback.Checked = True Then
           try
Dim objEmailMessage As System.Web.Mail.MailMessage
Dim objSMTPServer As System.Web.Mail.SmtpMail
objSMTPServer.SmtpServer = "mycomputername"
objEmailMessage = New System.Web.Mail.MailMessage
With objEmailMessage
.To = "destinationemail@address.com"
.From = txtFrom.Text
.Subject = "Great Job!"
.Body = "Want all my money?"
.BodyFormat = MailFormat.Html
End With
objSMTPServer.Send(objEmailMessage)
catch exc as exception
response.write(exc.innerexception.innerexception.message)
end try
          Else
          Response.Redirect("thankyou.html")
          End If
Else
'Do Whatever
End IF
     
     end sub

     
     </script>
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now