vb.net sub to have checkbox populate textbox in a user control

Hello,
I would like help with a sub  (vb.net) so that when a user clicks on a checkbox, an associated textbox gets populated with a text string like "April 23, 2010"
Codeaddict7423Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pacemaker9007Commented:
Hi, try this>
Public Class Form1

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
        End If
    End Sub
End Class

Open in new window

0
LotokCommented:
Make sure the checkbox has the property autopostback set to true, so the change is picked up when the check box is ticked.

If you want the date of when it is clicked, you can use the above code written by Pacmaker but have textbox1.text= now()
0
Codeaddict7423Author Commented:
thank you,
When I applied your suggestion, Visual Studio indicates the following: "Handles clause requires a WithEvents variable..."
Please help.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

LotokCommented:
Using vb.net at the top of the code page you have 2 drop downs, set the left one to your checkbox and the right one to the CheckBox1_CheckedChanged. It will automatically add a handles on to the end of the subname.

for example
Handles CheckBox1.CheckedChanged
0
Codeaddict7423Author Commented:
PaceMaker9007,
Thank you. At implementing your suggestion, VisualStudio2005 is i ndicating CheckBox1 is being used before it's assigned a value.
If CheckBox1.Checked = True Then
                TextBox1.Text = "April 23, 2010"
            Else
                TextBox1.Text = ""
            End If
Please help...
0
Codeaddict7423Author Commented:
Lotok:,
Thank you.  I did as you suggested,  however, i'm still getting an error indication: Handles clause requires a WithEvents variable." the two dropdowns are selected as "checbox1" and "CheckChanged" do i have to be in a particular control and then assign these two dropdowns?
0
LotokCommented:
When you select the checkbox on the left and checkchanged on the right it will create a SUB in the code page. Just be sure your text is in there.

Can you copy and paste the sub here so I can look for an error?
0
Codeaddict7423Author Commented:
Lotok:
Below, please find my code:
 Public Class Form1

        Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
           
            Dim TextBox1 As New TextBox
            Dim CheckBox1 As CheckBox
           
            If CheckBox1.Checked = True Then
                TextBox1.Text = "April 23, 2010"
            Else
                TextBox1.Text = ""
            End If
        End Sub
    End Class
-----------------
Handles CheckBox1.CheckedChanged --------indicates "handle clause requires a WithEvents...
If CheckBox1.Checked = True Then --------indicates variable checkbox1 is used before it has been assigned a value
----------------
Please please help...
0
Codeaddict7423Author Commented:
Lotok:
I have edited my code and it now looks like the following:
 Public Class Form1

        Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
           
            Dim TextBox1 As New TextBox
            Dim CheckBox1 As New CheckBox
           
            If CheckBox1.Checked = True Then
                TextBox1.Text = "April 23, 2010"
            Else
                TextBox1.Text = ""
            End If
       
       
       
        End Sub
    End Class
---------
VisualBasic indicates the only error as:
Handles CheckBox1.CheckedChanged --------indicates "handle clause requires a WithEvents...



0
LotokCommented:
The first piece of code in the codebox is the Sub syntax which appears to match yours, unless you are using raiseevent somewhere, that error doesnt really make sense...

Create a new clean form, drop on a checkbox and create a checkedchanged sub as decribed above, does the error appear there?

You shouldnt have to do the line
dim checkbox1 as checkbox

If there is already a checkbox on the form, same with the textbox if it already exists on the form. You just need these lines

If CheckBox1.Checked = True Then
                TextBox1.Text = "April 23, 2010"
            Else
                TextBox1.Text = ""
            End If

Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
 
End Sub

Open in new window

0
Codeaddict7423Author Commented:
Lotok,
thanks for the quick reply. The form I'm editing is a user control *.ascx) using VB.NET 2.0.
The form's name is as follows:  <HGACServerControls:RSVPForm ID="RSVPForm1" runat="server" > 
If i comment out "Dim CheckBox1 as New CheckBox", VS indicates "Name CheckBox1 is not declared". The same for "TextBox1",
All I'm trying to do is to get a date on a textbox when a user clicks on a checkbox. this textbox should display "April 23, 2010" to indicate their choice for an event. there is one other date, but I just want one to work, then i'll copy the other function...
0
LotokCommented:
On the user control, have you dropped a textbox and checkbox on using the designer? If not then do so.
Remember to do this on the usercontrol, not the form.

The user control is later dropped onto the form which will add the control/code.

Make sure you are using the code behind file for the user control and not for the form.



0
Codeaddict7423Author Commented:
Lotok:
Thank you. I did as youi suggested. I attempted to run the file and got this:

Compiler Error Message: BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Line 22:         If CheckBox1.Checked = True Then
Line 23:             TextBox1.Text = "April 23, 2010"
0
Codeaddict7423Author Commented:
Lotok:
Perhaps this provides a better idea of what i have:
---------------------------------
<script runat="server">
   
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
       
        'If (Not IsPostBack) Then
       
   
       
    End Sub
   
   
    Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
        End If

    End Sub
</script>
--------------------
0
LotokCommented:
I have just created the project on my VS2008 and its working fine.
Here is my code

The user control has a textbox and a checkbox dropped on in designer mode.
The form loads the user control in the below code.

If you want to give me an email address, I cam email you the project. EE wont let me upload the file types needed
ON THE FORM

Public Class Form1


    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Dim x As New UserControl1
        Me.Controls.Add(x)
    End Sub
End Class


ON THE USER CONTROL

Public Class UserControl1

    Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
        End If

    End Sub
End Class

Open in new window

0
LotokCommented:
Its ASP.NET? AHHHH lol

Do you have your checkbox and textbox in the ASP markup or are you creating them dynamically?
0
LotokCommented:
Also have you declared the user control on the ASP.NET page?
0
Codeaddict7423Author Commented:
Lotok:
thanks for  the quick reply. The checkbox is not generated dynamically. All controls in the UserControl form are structured under servercontrols named "RSVPForm1". under that is a "<AdditionalFormControls>" and then the table with the controls start. this is a usercontrol that gets imported into a CMS called "TeamSite, ver 5.7.1" TeamSite generates the page inside which this usercontrol lives. THe code below may explain what I'm doing:
--------
<%@ Control Language="VB" ClassName="RSVP_FEMAnopay" Debug="true" %>

<script runat="server">
   
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
       
        'If (Not IsPostBack) Then
    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
       
        If CheckBox1.Checked = True Then
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
        End If

    End Sub
</script>

<div align="center"><p><img title="FEMA Workshops" height="108" alt="FEMA Workshops" hspace="0" src="/community/water/rfmc/images/logo.gif" width="600" align="middle" border="0" /></p></div>
               

<p style="font-size: x-small; color: red; text-align: right">

   
   
    * denotes required fields.<br />
 
 <HGACServerControls:RSVPForm ID="RSVPForm1" runat="server" CreditCardOnly="false" RSVPContactEmail="luis.hernandez@h-gac.com" RSVPCode="FEMA Workshop Registration Form" Width="572px" ShowBilling="false" ShowBillingTotalLabel="false" > 
       
    <AdditionalFormControls>
        &nbsp;
-----------------
        after this the table with the individual controls start
0
LotokCommented:
I need to get to bed, I will have a look at this for you tomorrow (about 7 hrs time).
I will do as I did when I thought it was a winforms app. Just create the code here and test it.

Hang in there.
0
Pacemaker9007Commented:
Is the checkbox1 located in the table with the individual controls? Could you paste that part of the code as well
0
LotokCommented:
If you can post the code including the table and the ASP markup showing the checkbox etc.
If its really big, then just attach it as a file.
0
Codeaddict7423Author Commented:
Lotok:
Hello,
Below, please find my user control file. name: RSVP_FEMAnopay.ascx
-------
<%@ Control Language="VB" ClassName="RSVP_FEMAnopay" Debug="true" %>

<script runat="server">
   
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
       
        'If (Not IsPostBack) Then
        ' dd = RSVPForm1.FindControl("txt_DateOfWorkshop_01")
           
        ' dd.Items.Add(New ListItem("April23", " April 23,"))
        ' dd.Items.Add(New ListItem("May11", " May 11,"))
           
        'End If
       
       
       
       
    End Sub


   
   
   
    Public Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
       
        If CheckBox1.Checked = True Then
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
        End If

    End Sub
</script>

<div align="center"><p><img title="FEMA Workshops" height="108" alt="FEMA Workshops" hspace="0" src="/community/water/rfmc/images/logo.gif" width="600" align="middle" border="0" /></p></div>
               

<p style="font-size: x-small; color: red; text-align: right">

   
   
    * denotes required fields.<br />
 
 <HGACServerControls:RSVPForm ID="RSVPForm1" runat="server" CreditCardOnly="false" RSVPContactEmail="luis.hernandez@h-gac.com" RSVPCode="FEMA Workshop Registration Form" Width="572px" ShowBilling="false" ShowBillingTotalLabel="false" > 
   
   
   
    <AdditionalFormControls>
        &nbsp;
       
         <table width="620" cellpadding="0" cellspacing="0" style="border-color:blue" border="0">
     <tr>
  <td colspan="4" style="width:100%" valign="top" align="left"><strong><span style="color:crimson">Contact Information</span></strong><br /></td>
  </tr>
  <tr>
  <td colspan="4" style="width:100%" valign="top" align="center">&nbsp;&nbsp; </td>
  </tr>

    <tr>
   <td style="text-align: right; white-space: nowrap; width: 30%"><asp:Label ID="Label2" runat="server" AssociatedControlID="tbFName" Text="First Name:"></asp:Label>&nbsp;&nbsp;</td>    
       <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbFName" runat="server" Width="190px"></asp:TextBox></span></td>
     <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%"><span style="color: red">*</span>&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbFName" Display="Dynamic" ErrorMessage="First Name is required"    EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator>   </td></tr>
     
     
      <tr>
   <td style="text-align: right; white-space: nowrap; width: 30%"><asp:Label ID="Label1" runat="server" AssociatedControlID="tbLName" Text="Last Name:"></asp:Label>&nbsp;&nbsp;</td>    
       <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbLName" runat="server" Width="190px"></asp:TextBox></span></td>
     <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%"><span style="color: red">*</span>&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator9" 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; width: 30%"><asp:Label ID="Label6" runat="server" AssociatedControlID="tbTitle" Text="Title:"></asp:Label> &nbsp;</td>
     <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbTitle" runat="server" Width="190px"></asp:TextBox> </span> </td>
     <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%">&nbsp;     </td>
       </tr>
     <tr>
   <td style="text-align: right; white-space: nowrap; width: 30%"><asp:Label ID="Label3" runat="server" AssociatedControlID="tbOrganization" Text="Organization:"></asp:Label>&nbsp;&nbsp;</td>
   <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbOrganization" runat="server" Width="190px"></asp:TextBox></span></td>
    <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%"><span style="color: red">*</span>&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator2" 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; width: 30%"><asp:Label ID="Label100" runat="server" AssociatedControlID="tbAddres" Text="Address:"></asp:Label> &nbsp;</td>
     <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbAddres" runat="server" Width="190px"></asp:TextBox></span> </td>
     <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%"><span style="color: red">*</span>&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="tbAddres" ErrorMessage="Address is required" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator></td>
       </tr>
  <tr>
     <td style="text-align: right; white-space: nowrap; width: 30%"><asp:Label ID="Label8" runat="server" AssociatedControlID="tbCity" Text="City:"></asp:Label> &nbsp;</td>
        <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbCity" runat="server" Width="190px"></asp:TextBox> </span> </td>
     <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%"><span style="color: red">*</span>&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator6" 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; width: 30%"><asp:Label ID="Label9" runat="server" AssociatedControlID="tbState" Text="State:"></asp:Label>   &nbsp;</td>
     <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbState" runat="server" Width="190px"></asp:TextBox>  </span> </td>
     <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%"><span style="color: red">*</span>&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator7" 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; width: 30%"><asp:Label ID="Label10" runat="server" AssociatedControlID="tbZip" Text="Zip Code:"></asp:Label>  &nbsp;</td>
     <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbZip" runat="server" Width="190px"></asp:TextBox>  </span> </td>
     <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%"><span style="color: red">*</span>&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="tbZip" ErrorMessage="Zip Code is required" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator>     </td>
       </tr>
     
     
     
     
     <tr>
   <td style="text-align: right; white-space: nowrap; width: 30%"><asp:Label ID="Label5" runat="server" AssociatedControlID="tbPhone" Text="Phone #:"></asp:Label>&nbsp;&nbsp;</td>
   <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbPhone" runat="server" Width="190px"></asp:TextBox></span> </td>
   <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%"><span style="color: red">*</span>&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator4" 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; width: 30%"><asp:Label ID="Label11" runat="server" AssociatedControlID="tbCellPhone" Text="Cell Phone #:"></asp:Label>  &nbsp;</td>
     <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbCellPhone" runat="server" Width="190px"></asp:TextBox> </span> </td>
     <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%">&nbsp;     </td>
       </tr>
       
       <tr>
   <td style="text-align: right; white-space: nowrap; width: 30%"><asp:Label ID="Label4" runat="server" AssociatedControlID="tbEmail" Text="Email:"></asp:Label>&nbsp;&nbsp;</td>
   <td style="text-align: left; white-space: nowrap; width: 25%"><span><asp:TextBox ID="tbEmail" runat="server" Width="190px"></asp:TextBox></span></td>
   
   <td colspan="2" style="text-align: left; white-space: nowrap; width: 20%"><span style="color: red">*</span>&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ControlToValidate="tbEmail" ErrorMessage="Email is required" Display="Dynamic" EnableClientScript="true" SetFocusOnError="true"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" 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 colspan="4" style="width:100%" valign="top" align="center">&nbsp; </td>
  </tr>
  <tr>
  <td colspan="4" style="width:100%" valign="top" align="center"><hr /> </td>
  </tr>
     <tr>
  <td colspan="4" style="width:100%" valign="top" align="center">&nbsp; </td>
  </tr>
  <tr>
  <td colspan="4" style="width:100%" valign="top" align="left"><strong><span style="color:crimson">Workshop Information</span></strong><br /> </td>
  </tr>
  <tr>
  <td colspan="4" style="width:100%" valign="top" align="center">&nbsp;&nbsp; </td>
  </tr>
   
   <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%">
   <asp:Label ID="lblWorkshop_01" runat="server" AssociatedControlID="Workshop_1">Attend April 23 Workshop:</asp:Label>

    </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span>

 <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
   
   
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
   
   


</span>  

 </td>
 </tr>

   
 
  <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">Workshop 1:&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="color:#4b8a08; font-size:11px">Local Official’s Guide to Coastal Construction</span></td>
 </tr>
  <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">Date:&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="color:#08088a; font-size:11px">Friday, April 23, 2010</span></td>
 </tr>
   <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">Time:&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="font-size:11px">8:00 am – 5:00 pm</span></td>
 </tr>
  <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">Location:&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="font-size:11px"><a class="null" title="Directions Community Resource Center" href="http://www.unitedwayhouston.org/default/pdfs/uw_directions.pdf">United Way<br />Community Resource Center</a><br />
50 Waugh Drive<br />
Houston, TX 77007</span></td>
 </tr>
   <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">Cost:&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="font-size:11px">There is no fee for this workshop.</span></td>
 </tr>
 
 
 
  <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="font-size:11px">&nbsp; </span></td>
 </tr>

 

  <tr>
  <td colspan="4" style="width:100%" valign="top" align="center"><hr /> </td>
  </tr>
 
  <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%">
   <asp:Label ID="lblWorkshop_02" runat="server" AssociatedControlID="Workshop_2">Attend May 11 Workshop:</asp:Label>
   </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span>
<asp:CheckBox ID="Workshop_2" runat="server" AutoPostBack="False" Font-Size= "X-Small" Text=" "  /></span>&nbsp;  </td>
 </tr>
   
 
  <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">Workshop 2:&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="color:#4b8a08; font-size:11px">Coastal Construction Workshop for Homebuilders and <br />
Introduction to Coastal Foundation Design and Construction for Local Officials
</span></td>
 </tr>
 <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">Date:&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="color:#08088a; font-size:11px">Tuesday, May 11, 2010</span></td>
 </tr>
 <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">Time:&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="font-size:11px">8:00 am – 5:00 pm</span></td>
 </tr>
  <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">Location:&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="font-size:11px"><a class="null" title="Directions to H-GAC" href="http://www.h-gac.com/contact/Map/default.aspx">Houston-Galveston Area Council</a><br />
3555 Timmons Lane</a><br />
2nd Floor Conference Room A, Suite 120<br />
Houston, TX 77027</span></td>
 </tr>
   <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">Cost:&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="font-size:11px">There is no fee for this workshop.</span></td>
 </tr>
 
 
  <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"><span style="font-size:11px">&nbsp;&nbsp;</span> </td>
   <td colspan="3" style="text-align: left; vertical-align:top; width: 70%; background-color:white"><span style="font-size:11px">&nbsp; </span></td>
 </tr>

 <tr>
  <td colspan="4" style="width:100%" valign="top" align="center"><hr /> </td>
  </tr>
<tr>
  <td colspan="4" style="width:100%" valign="top" align="center">&nbsp;&nbsp; </td>
  </tr>
  <tr>
   <td style="text-align: right; vertical-align:top; white-space: nowrap; width: 30%"> <asp:Label ID="Label7" runat="server"

Text="Your Comments:&nbsp;&nbsp;" AssociatedControlID="tbComments"></asp:Label></td>    
       <td colspan="3" style="text-align: left;  width: 70%"><span>
       <asp:TextBox ID="tbComments" runat="server" TextMode="MultiLine" Height="80" Width="90%"></asp:TextBox>
       </td>
     </tr>
   
 
     
    </table>    
        <br /> <br />
       
       
</AdditionalFormControls>

<RSVPResponseText>
            <p>
                <font face="Arial, Helvetica, sans-serif">
               
Thank you for registering!<br /> <br />
For more information about the event please contact:
<br />
Erin Livingston<br />
(832) 681-2525<br />
<a href="mailto:erin.livingston@h-gac.com">erin.livingston@h-gac.com</a>.


</font></p>
</RSVPResponseText>

</HGACServerControls:RSVPForm>
    &nbsp;</p>

0
Pacemaker9007Commented:
In the part where you have your checkbox, try to remove this:

OnCheckedChanged="CheckBox1_CheckedChanged"

see if it helps.
0
Codeaddict7423Author Commented:
I did that. i'm still getting the following 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: BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Source Error:

 

Line 22:    
Line 23:    
Line 24:     Public Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Line 25:        
Line 26:         If CheckBox1.Checked = True Then
 
0
Pacemaker9007Commented:
Ok, please return back the OnCheckedChanged="CheckBox1_CheckedChanged", but remove the Handles Checkbox1.CheckedChanged.
0
Codeaddict7423Author Commented:
Ok, now i'm getting a simple error about declaring:
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 'CheckBox1' is not declared.

Source Error:

 

Line 24:     Public Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Line 25:        
Line 26:         If CheckBox1.Checked = True Then
Line 27:             TextBox1.Text = "April 23, 2010"
Line 28:         Else
 
---------
below is my sub syntax:
    Public Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
       
        If CheckBox1.Checked = True Then
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
        End If

    End Sub
0
Codeaddict7423Author Commented:
I got the form to run without returning errors; but it still doesnot work. My sub code is as follows:
--------------
Public Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
       
        Dim CheckBox1 As New CheckBox
        Dim TextBox1 As New TextBox
       
        If CheckBox1.Checked = True Then
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
        End If

    End Sub
----------
0
Codeaddict7423Author Commented:
Hello,
I've edited my sub to read like this:
--------
 Public Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.CheckBox1.CheckedChanged
       
        Dim CheckBox1 As New CheckBox
        Dim TextBox1 As New TextBox
       
        If CheckBox1.Checked = True Then
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
        End If

    End Sub
-------

The line "CheckBox1.CheckedChanged" is indicating a error like "End of Statement Expected"

Please help!!!
0
Codeaddict7423Author Commented:
Hello,
 I'm trying something new, however it's not working, perhaps you can help  me.
Sub syntax:
-----------
Public Sub chkchk_checked(ByVal sender As Object, ByVal e As System.EventArgs)
       
        Dim chkchk As CheckBox = CType(sender, CheckBox)
        Dim TextBox1 As New TextBox
        If chkchk.Checked = True Then
            'call your SP
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
           
        End If

    End Sub
   
-------------
Checkbox code:
-------------
    <asp:CheckBox ID="chkchk" runat="server" OnCheckedChanged="chkchk_checked" AutoPostBack="true" />

   <asp:TextBox ID="TextBox1" runat="server" BackColor="yellow"></asp:TextBox>
    <br />
-------------
Please help!

0
LotokCommented:
Try this


Public Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.CheckBox1.CheckedChanged
       
        Dim  chk as checkbox = Ctype(Page.findcontrol("checkbox1"), checkbox)
        Dim txt as textbox = Ctype(Page.findcontrol("textbox1"), textbox)
       
        If chk.Checked = True Then
           txt.Text = "April 23, 2010"
        Else
           txt.Text = ""
        End If

    End Sub
0
Codeaddict7423Author Commented:
Thank you. I copied your code and VisualStudio is indicating teh following:
CheckBox1.CheckedChanged (error indicator stating: "End of Statement Expected" )
0
LotokCommented:
double click the error, it will take you to the line in question.
copy and paste that section
0
Codeaddict7423Author Commented:
below, please find the compilation error i'm getting:
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: BC30590: Event 'CheckBox1' cannot be found.

Source Error:

 

Line 22:    
Line 23:    
Line 24:     Public Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.CheckBox1.CheckedChanged
Line 25:        
Line 26:         Dim chk As CheckBox = CType(Page.FindControl("checkbox1"), CheckBox)
 

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

0
Codeaddict7423Author Commented:
Hello, I modified the sub as follows:
    Public Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
       
        Dim chk As CheckBox = CType(Page.FindControl("CheckBox1"), CheckBox)
        Dim txt As TextBox = CType(Page.FindControl("TextBox1"), TextBox)
       
        If chk.Checked = True Then
            txt.Text = "April 23, 2010"
        Else
            txt.Text = ""
        End If
       
    End Sub
--------------------

VS is indicating a "Handles requires a 'withEvents' variable"

Please help!!!!!
0
Codeaddict7423Author Commented:
Hello,
I 've modified the sub as follows:
    Private Sub CheckBox1_CheckChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1_CheckedChanged.
       
        Dim chk As CheckBox = CType(Page.FindControl("CheckBox1"), CheckBox)
        Dim txt As TextBox = CType(Page.FindControl("TextBox1"), TextBox)
       
        If chk.Checked = True Then
            txt.Text = "April 23, 2010"
        Else
            txt.Text = ""
        End If
       
    End Sub
------------------

VS is indicating an error at the end of the "CheckBox1_CheckedChanged." as "identifyer expected"
copiler eror as follows:
BC30287: '.' expected.

0
LotokCommented:
OK so I can be very clear. I want to make sure I am clear before i recreate the ASP.NET scenario here.

You need to have a usercontrol, which contains a table. It is not a table control, just a standard XHTML table. Within that, you will have a checkbox and a textbox.
You want the checkbox to autopost back, so when checked it shows a date and then unchecked it clears.

That about right?
0
Codeaddict7423Author Commented:
Lotok,
thanks for the quick reply. Yes, I have a user control. in that user control there is a script as follows:
<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        'If (Not IsPostBack) Then
        ' dd = RSVPForm1.FindControl("txt_DateOfWorkshop_01"
        'End If
    End Sub
    Private Sub CheckBox1_CheckChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1_CheckedChanged
        Dim chk As CheckBox = CType(RSVPForm1.FindControl("CheckBox1"), CheckBox)
        Dim txt As TextBox = CType(RSVPForm1.FindControl("TextBox1"), TextBox)
        If chk.Checked = True Then
            txt.Text = "April 23, 2010"
        Else
            txt.Text = ""
        End If
    End Sub
</script>

After this script, there is a form declaration as follows:

 <HGACServerControls:RSVPForm ID="RSVPForm1" runat="server" CreditCardOnly="false" RSVPContactEmail="luis.hernandez@h-gac.com" RSVPCode="FEMA Workshop Registration Form" Width="572px" ShowBilling="false" ShowBillingTotalLabel="false" >   
    <AdditionalFormControls>

Now there is a table with rows and cells. in one of those cells, there is a checkbox control (CheckBox1) and a TextBox control (TextBox1).
I am attempting to write code such that when a user clicks on the checkbox control (CheckBox1) TextBox1 control displays a text string ("April23, 2010") and when the user unclicks the checkbox control, the textbox control (TextBox1) clears.

My code is as follows:
    Private Sub CheckBox1_CheckChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1_CheckedChanged
       
        Dim chk As CheckBox = CType(RSVPForm1.FindControl("CheckBox1"), CheckBox)
        Dim txt As TextBox = CType(RSVPForm1.FindControl("TextBox1"), TextBox)
       
        If chk.Checked = True Then
            txt.Text = "April 23, 2010"
        Else
            txt.Text = ""
        End If
       
    End Sub
VS indicates that there is a missing (.) at the end of "CheckBox1_CheckedChanged" when i add it , i get an indication that "an identifier is expected"...


When i run t his code, i get the following 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: BC30203: Identifier expected.

Source Error:
Line 18:     End Sub
Line 19:
Line 20:     Private Sub CheckBox1_CheckChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1_CheckedChanged.
Line 21:        
Line 22:         Dim chk As CheckBox = CType(RSVPForm1.FindControl("CheckBox1"), CheckBox)
 

Source File: Y:\default\main\www\WORKAREA\Common\htdocs\uc\RSVP\RSVP_FEMAnopay.ascx    Line: 20
--------

Please help!!!
0
LotokCommented:
OK, So I have created an ASP.NET usercontrol named UserControl2. That control contains a table with the checkbox and textbox. I have placed the user control on a aspx page to test and it works fine.

Now you will see I excluded the form declaration.
<HGACServerControls:RSVPForm ID="RSVPForm1" runat="server" CreditCardOnly="false" RSVPContactEmail="luis.hernandez@h-gac.com" RSVPCode="FEMA Workshop Registration Form" Width="572px" ShowBilling="false" ShowBillingTotalLabel="false" >   
    <AdditionalFormControls>

What is the HGACServer controls, something you wrote? or someone elses code?

Now as I said, the below code work.
If you create a similar test at your end it will help you troubleshoot.

Please follow these steps.

1) Create a user control.
2) Paste the code from CODE SAMPLE 1 into that control.
3) Drop the control on an aspx page in designer mode.
4) you will see dropping the control on creates 2 new lines of markup on the aspx page, similar to code sample 2

Confirm you have that working then we can take it from there.
CODE SAMPLE 1*********************
**********************************

<script runat="server">

    Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If CheckBox1.Checked = True Then
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
        End If
    End Sub
</script>


<table>
<tr>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</tr>
<tr>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
</tr>
</table>


CODE SAMPLE 2********************
*********************************

<%@ Register src="UserControl2.ascx" tagname="UserControl2" tagprefix="uc1" %>

<uc1:UserControl2 ID="UserControl21" runat="server" />

Open in new window

0
Codeaddict7423Author Commented:
Lotok,
thank you for your help. i have done the steps you suggested.
When i add the code block:
<script runat="server">
 
    Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If CheckBox1.Checked = True Then
            TextBox1.Text = "April 23, 2010"
        Else
            TextBox1.Text = ""
        End If
    End Sub
</script>
VS is indicating the following: CheckBox1 is not declared and TextBox1 is not declared
In the past, I've fixed this by declaring: Dim CheckBox1 as New Checkbox and
Dim TextBox1 as New Textbox
that seems to make VS happy. should I do that now?
0
LotokCommented:
No, below that code block on my example is some markup (below). That is where the controls are declared.
can you paste your full page of code/markup once you complete this as a comparison? From your previous posts I see you dont use a seperate code page, I have allowed for that in my example, it all belongs on 1 page.



<table>
<tr>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</tr>
<tr>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
</tr>
</table>

Open in new window

0
Codeaddict7423Author Commented:
it worked...let me try it on the actual form....
0
Codeaddict7423Author Commented:
It works on the actual form. now for tweaking the look and feel, but at least, the code works. THANK YOU SO VERY MUCH!!!
0
LotokCommented:
No probs, glad I could help.
We got there eventually :D
0
LotokCommented:
Hey CodeAddict, can you accept the solution to close the request?

Many Thanks
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.