Solved

ASP.NET 2.0 Wizard FindControl Textbox Email

Posted on 2008-10-14
6
886 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 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