Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.NET 2.0 Wizard FindControl Textbox Email

Posted on 2008-10-14
6
Medium Priority
?
897 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 22

Accepted Solution

by:
prairiedog earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

886 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