Solved

ASP.NET 2.0 Wizard FindControl Textbox Email

Posted on 2008-10-14
6
882 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 22

Accepted Solution

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

Author Comment

by:sri-admin
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

6 Experts available now in Live!

Get 1:1 Help Now