?
Solved

ASP.NET 2.0 Wizard FindControl Textbox Email

Posted on 2008-10-14
6
Medium Priority
?
906 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
Independent Software Vendors: 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!

 
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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

621 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