Solved

ASP.NET 2.0 Wizard FindControl Textbox Email

Posted on 2008-10-14
6
883 Views
Last Modified: 2013-11-07
Hello.  Attempting to send a confirmation email after a user has registered information into a database.  This is a simple task.  What's confusing for me is that I need to find the value inside of a textbox in the wizard, and use that for the email address, and so far have had no luck.  The code for the email is:

Sub BidderEmailMessage()

        Dim strBody As String
        Dim BidderEmail As TextBox
        BidderEmail = Wizard1.FindControl("emailText")
        Dim mm As New MailMessage(Membership.GetUser.Email, BidderEmail.Text)

        strBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbCrLf _
  & "<html>" & vbCrLf _
  & "<head>" & vbCrLf _
  & " <title>Email</title>" & vbCrLf _
  & " <meta http-equiv=Content-Type content=""text/html; charset=iso-8859-1"">" & vbCrLf _
  & "</head>" & vbCrLf _
  & "<body>" & vbCrLf _
  & " <h2>Email</h2>" & vbCrLf _
  & " <p>" & "<img border='0' src='../Images/logo_new.jpg' width='505' height='152'>" & "</img>" & "</p>" & vbCrLf _
  & " <font size=""-1"">" & vbCrLf _
  & "  <br><br>Please address all concerns to " & "<a href='mailto:support@here.com'>" & "Support" & "</a>" & vbCrLf _
  & " </font>" & vbCrLf _
  & "</body>" & vbCrLf _
  & "</html>" & vbCrLf

        mm.Subject = "Thank you for Registering"
       
        mm.Body = strBody
        mm.IsBodyHtml = True

        Dim smtp As New SmtpClient
        smtp.Send(mm)

    End Sub

The wizard code is:

<asp:Wizard ID="Wizard1" runat="server" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ActiveStepIndex="0"  StartNextButtonText="Agree and Continue" DisplaySideBar="False" Width="100%" OnNextButtonClick="Wizard1_NextButtonClick">
        <WizardSteps>
            <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
<div class="container">
                <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert" Width="444px" Height="921px">
                  <InsertItemTemplate>
           <table cellpadding="3" style="width: 713px" cellspacing="0">
                <tr>
                    <td>Something</td>
                </tr>
            </table>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        &nbsp;
                    </ItemTemplate>
                </asp:FormView>
       </div>          
            </asp:WizardStep>
            <asp:WizardStep runat="server" Title="Step 2" AllowReturn="False" ID="w9">
            <div class="container">
                <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert" Width="444px" Height="921px">
                  <InsertItemTemplate>
           <table cellpadding="3" style="width: 713px" cellspacing="0">
                <tr>
                    <td>Something</td>
                </tr>
            </table>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        &nbsp;
                    </ItemTemplate>
                </asp:FormView>
       </div>              
            </asp:WizardStep>
            <asp:WizardStep runat="server" Title="Step 3" AllowReturn="False" ID="ContactInfo">
            <div class="container">
                <asp:FormView ID="FormView2" runat="server" DataKeyNames="BuyerID" DataSourceID="SqlDataSource2" DefaultMode="Edit" Width="580px">
                <EditItemTemplate>
                    <table style="width: 561px; height: 145px">
                            <tr>
                                <td class="MyTableCell" colspan="5" style="height: 31px">
                                    <strong><span style="font-size: 14pt">Contact Information</span></strong></td>
                            </tr>
                            <tr>
                                <td style="width: 159px; height: 26px;">
                                    Enter Email Address:</td>
                                <td colspan="2" style="height: 26px">
                                    <asp:TextBox ID="emailText" runat="server" Text='<%# Bind("EmailAddress") %>'></asp:TextBox>
                                    <asp:RegularExpressionValidator ID="emailRegExp" runat="server" ControlToValidate="emailText"
                                        ErrorMessage="Email Format Incorrect" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">!</asp:RegularExpressionValidator>
                                    <asp:RequiredFieldValidator ID="reqEmail" runat="server" ControlToValidate="emailText"
                                        ErrorMessage="Email Address is Required">!</asp:RequiredFieldValidator></td>
                                <td style="width: 100px; color: #000000; height: 26px;">
                                </td>
                                <td style="width: 100px; color: #000000; height: 26px;">
                                </td>
                            </tr>
                            <tr style="color: #000000">
                                <td style="width: 159px">
                                    Enter Phone Number:</td>
                                <td colspan="2">
                                    <asp:TextBox ID="phoneText" runat="server" Text='<%# Bind("BUYER_TELEPHONE") %>'></asp:TextBox>
                                    <asp:RegularExpressionValidator ID="regExpPhone" runat="server" ControlToValidate="phoneText"
                                        ErrorMessage="Please Enter your Phone Number xxx-xxx-xxxx." ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">!</asp:RegularExpressionValidator>
                                    <asp:RequiredFieldValidator ID="reqPhone" runat="server" ControlToValidate="phoneText"
                                        ErrorMessage="Phone Number is Required">!</asp:RequiredFieldValidator></td>
                                <td style="width: 100px">
                                </td>
                                <td style="width: 100px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 159px">
                                    </td>
                                <td colspan="2">
                                    Format XXX-XXX-XXXX</td>
                                <td style="width: 100px">
                                </td>
                                <td style="width: 100px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 159px">
                                </td>
                                <td colspan="2">
                                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" Width="196px" />
                                </td>
                                <td style="width: 100px">
                                </td>
                                <td style="width: 100px">
                                </td>
                            </tr>
                        </table>
               
                </EditItemTemplate>
                    <ItemTemplate>
                        &nbsp;
                    </ItemTemplate>
                </asp:FormView>
             </div>
            </asp:WizardStep>
            <asp:WizardStep ID="WizardStep2" runat="server" AllowReturn="False" Title="Step 4">
            <div class="container">
                <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert" Width="444px" Height="921px">
                  <InsertItemTemplate>
           <table cellpadding="3" style="width: 713px" cellspacing="0">
                <tr>
                    <td>Something</td>
                </tr>
            </table>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        &nbsp;
                    </ItemTemplate>
                </asp:FormView>
       </div>          
            </asp:WizardStep>
        </WizardSteps>
    </asp:Wizard>

Please note that the value I'm attempting to access is inside of the ContactInfo WizardStep, and it's called "emailText".  I thought at first it was my email code, but that checks out, I can't even place the value of the "emailText" inside of a label control, which tells me that there must be something I'm missing.  

Any help would be greatly appreciated.

<script runat="server">
Sub BidderEmailMessage()
 
        Dim strBody As String
        Dim BidderEmail As TextBox
        BidderEmail = Wizard1.FindControl("emailText")
        Dim mm As New MailMessage(Membership.GetUser.Email, BidderEmail.Text)
 
        strBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbCrLf _
  & "<html>" & vbCrLf _
  & "<head>" & vbCrLf _
  & " <title>Email</title>" & vbCrLf _
  & " <meta http-equiv=Content-Type content=""text/html; charset=iso-8859-1"">" & vbCrLf _
  & "</head>" & vbCrLf _
  & "<body>" & vbCrLf _
  & " <h2>Email</h2>" & vbCrLf _
  & " <p>" & "<img border='0' src='../Images/logo_new.jpg' width='505' height='152'>" & "</img>" & "</p>" & vbCrLf _
  & " <font size=""-1"">" & vbCrLf _
  & "  <br><br>Please address all concerns to " & "<a href='mailto:support@here.com'>" & "Support" & "</a>" & vbCrLf _
  & " </font>" & vbCrLf _
  & "</body>" & vbCrLf _
  & "</html>" & vbCrLf
 
        mm.Subject = "Thank you for Registering"
        
        mm.Body = strBody
        mm.IsBodyHtml = True
 
        Dim smtp As New SmtpClient
        smtp.Send(mm)
 
    End Sub
</script>
 
<asp:Wizard ID="Wizard1" runat="server" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ActiveStepIndex="0"  StartNextButtonText="Agree and Continue" DisplaySideBar="False" Width="100%" OnNextButtonClick="Wizard1_NextButtonClick">
        <WizardSteps>
            <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
<div class="container">
                <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert" Width="444px" Height="921px">
                  <InsertItemTemplate>
           <table cellpadding="3" style="width: 713px" cellspacing="0">
                <tr>
                    <td>Something</td>
                </tr>
            </table>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        &nbsp;
                    </ItemTemplate>
                </asp:FormView>
       </div>           
            </asp:WizardStep>
            <asp:WizardStep runat="server" Title="Step 2" AllowReturn="False" ID="w9">
            <div class="container">
                <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert" Width="444px" Height="921px">
                  <InsertItemTemplate>
           <table cellpadding="3" style="width: 713px" cellspacing="0">
                <tr>
                    <td>Something</td>
                </tr>
            </table>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        &nbsp;
                    </ItemTemplate>
                </asp:FormView>
       </div>               
            </asp:WizardStep>
            <asp:WizardStep runat="server" Title="Step 3" AllowReturn="False" ID="ContactInfo">
            <div class="container">
                <asp:FormView ID="FormView2" runat="server" DataKeyNames="BuyerID" DataSourceID="SqlDataSource2" DefaultMode="Edit" Width="580px">
                <EditItemTemplate>
                    <table style="width: 561px; height: 145px">
                            <tr>
                                <td class="MyTableCell" colspan="5" style="height: 31px">
                                    <strong><span style="font-size: 14pt">Contact Information</span></strong></td>
                            </tr>
                            <tr>
                                <td style="width: 159px; height: 26px;">
                                    Enter Email Address:</td>
                                <td colspan="2" style="height: 26px">
                                    <asp:TextBox ID="emailText" runat="server" Text='<%# Bind("EmailAddress") %>'></asp:TextBox>
                                    <asp:RegularExpressionValidator ID="emailRegExp" runat="server" ControlToValidate="emailText"
                                        ErrorMessage="Email Format Incorrect" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">!</asp:RegularExpressionValidator>
                                    <asp:RequiredFieldValidator ID="reqEmail" runat="server" ControlToValidate="emailText"
                                        ErrorMessage="Email Address is Required">!</asp:RequiredFieldValidator></td>
                                <td style="width: 100px; color: #000000; height: 26px;">
                                </td>
                                <td style="width: 100px; color: #000000; height: 26px;">
                                </td>
                            </tr>
                            <tr style="color: #000000">
                                <td style="width: 159px">
                                    Enter Phone Number:</td>
                                <td colspan="2">
                                    <asp:TextBox ID="phoneText" runat="server" Text='<%# Bind("BUYER_TELEPHONE") %>'></asp:TextBox>
                                    <asp:RegularExpressionValidator ID="regExpPhone" runat="server" ControlToValidate="phoneText"
                                        ErrorMessage="Please Enter your Phone Number xxx-xxx-xxxx." ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">!</asp:RegularExpressionValidator>
                                    <asp:RequiredFieldValidator ID="reqPhone" runat="server" ControlToValidate="phoneText"
                                        ErrorMessage="Phone Number is Required">!</asp:RequiredFieldValidator></td>
                                <td style="width: 100px">
                                </td>
                                <td style="width: 100px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 159px">
                                    </td>
                                <td colspan="2">
                                    Format XXX-XXX-XXXX</td>
                                <td style="width: 100px">
                                </td>
                                <td style="width: 100px">
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 159px">
                                </td>
                                <td colspan="2">
                                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" Width="196px" />
                                </td>
                                <td style="width: 100px">
                                </td>
                                <td style="width: 100px">
                                </td>
                            </tr>
                        </table>
                
                </EditItemTemplate>
                    <ItemTemplate>
                        &nbsp;
                    </ItemTemplate>
                </asp:FormView>
             </div>
            </asp:WizardStep>
            <asp:WizardStep ID="WizardStep2" runat="server" AllowReturn="False" Title="Step 4">
            <div class="container">
                <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert" Width="444px" Height="921px">
                  <InsertItemTemplate>
           <table cellpadding="3" style="width: 713px" cellspacing="0">
                <tr>
                    <td>Something</td>
                </tr>
            </table>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        &nbsp;
                    </ItemTemplate>
                </asp:FormView>
       </div>           
            </asp:WizardStep>
        </WizardSteps>
    </asp:Wizard>

Open in new window

0
Comment
Question by:sri-admin
  • 4
  • 2
6 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 22713846
The TextBox is defined in a FormView control, try FindControl to get the FormView control first, then use FindControl on the FormView to get the TextBox.
0
 

Author Comment

by:sri-admin
ID: 22714088
First off, thank you for the suggestion.  
I used the following to reference the control:

        Dim BidderEmail As TextBox
        BidderEmail = FormView1.FindControl("EditItemTemplate").FindControl("emailText")

and still get a NullExceptionError.
Is this correct, or was I missing something?
0
 

Author Comment

by:sri-admin
ID: 22714096
Sorry, meant to say:


       Dim BidderEmail As TextBox
        BidderEmail = FormView2.FindControl("EditItemTemplate").FindControl("emailText")

Note the only difference is that I called FormView2 instead of Formview1.
Sorry.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 22714147
Dim fv As FormView = CType(Wizard1.FindControl("FormView2"), FormView)
Dim BidderEmail As TextBox = CType(fv.FindControl("emailText"), TextBox)
0
 

Author Comment

by:sri-admin
ID: 22714662
Still no luck.  Not sure what's going on here.  I used those values, and tried the following:

response.write(BidderEmail)
response.write(BidderEmail.Text)
response.write(BidderEmail.ToString)
Me.TextBox2.Text = BidderEmail.Text
Me.TextBox2.Text = BidderEmail.ToString

and nothing is working.    
Any other suggestions?
0
 

Author Comment

by:sri-admin
ID: 22745063
OK, my apologies.  I used this, and finally noticed that with this, combined with the fact that I was attempting to send from a registered user email, (when the user is registering...duh!), so that was one of the flags.  Anyways, by using:

Dim fv As FormView = CType(Wizard1.FindControl("FormView2"), FormView)
Dim BidderEmail As TextBox = CType(fv.FindControl("emailText"), TextBox)
Dim mailTo As String = BidderEmail.Text

it works like a charm.
Thanks!!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delete HTML table rows 12 27
imap mails 1 22
export data table to excel in vb.net 10 21
Sql server insert 13 26
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

816 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

13 Experts available now in Live!

Get 1:1 Help Now