[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

How do I access the text out of an asp textbox in my code page for the page it's attached to?

Dear Experts!

I am very new to asp programming. I'm trying to process a linkpointAPI order using my asp.net page. Right now my issue is that every time my page loads (even after the postback) I need to take all the values that the user fills into the fields and I need to pass it to my linkpointapi thing. Anyways, here is my code part, which does not run. It crashes on the fillinformfields, saying that fld_bcompany is equal to nothing. That is why I cannot read the text property on the field. Based on the following code, Experts, what am I doing wrong?


Namespace LinkPointAPI_vb
    Public Class Order
        Inherits LinkPointTxn_Page
        ''Inherits System.Web.UI.Page
        Dim flagUserCreated As Boolean = False
        'Protected WithEvents fld_bname As System.Web.UI.WebControls.TextBox = Application.Item("fld_bname")
        'Protected fld_bcompany As System.Web.UI.WebControls.TextBox
        Protected fld_baddr1 As System.Web.UI.WebControls.TextBox
        Protected fld_bcity As System.Web.UI.WebControls.TextBox
        Protected fld_bstate As System.Web.UI.WebControls.TextBox
        Protected fld_bzip As System.Web.UI.WebControls.TextBox
        Protected fld_bphone As System.Web.UI.WebControls.TextBox
        Protected fld_saddr1 As System.Web.UI.WebControls.TextBox
        Protected fld_scity As System.Web.UI.WebControls.TextBox
        Protected fld_sstate As System.Web.UI.WebControls.TextBox
        Protected fld_szip As System.Web.UI.WebControls.TextBox



        Public Sub FillInFormFields()
            Session.Item("bcompany") = Me.fld_bcompany.text
        End Sub

        Public Sub OnCreatingUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles CreateUserWizard1.CreatingUser
            FillInFormFields()
            ParseFormData()
            ProcessOrder()
        End Sub



        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            If IsPostBack Then
                FillInFormFields()
                'Parse form data
                ParseFormData()
                'process(Order)
                ProcessOrder()
            End If
        End Sub

        Private Sub ProcessOrder()

            ' create order
            Dim op As LinkPointTransaction.LPOrderPart
            Dim order As LinkPointTransaction.LPOrderPart

            order = LinkPointTransaction.LPOrderFactory.createOrderPart("order")
            ' create a part we will use to build the order
            op = LinkPointTransaction.LPOrderFactory.createOrderPart()

            ' Build 'orderoptions'
            op.put("ordertype", "SALE")
            ' set transaction result
            op.put("result", Request.Form("result"))
            ' add 'orderoptions to order
            order.addPart("orderoptions", op)
            ' Build 'transactiondetails'
            op.clear()
            op.put("transactionorigin", Request.Form("origin"))
            ' add 'transactiondetails to order
            order.addPart("transactiondetails", op)
            ' Build 'merchantinfo'
            op.clear()
            op.put("configfile", configfile)
            ' add 'merchantinfo to order
            order.addPart("merchantinfo", op)

            ' Build 'payment'
            op.clear()
            op.put("subtotal", Request.Form("subtotal"))
            op.put("tax", Request.Form("tax"))
            op.put("shipping", Request.Form("shipping"))
            op.put("chargetotal", Request.Form("total"))
            ' add 'payment to order
            order.addPart("payment", op)

            ' Build 'creditcard'
            op.clear()
            op.put("cardnumber", cardnumber)
            op.put("cardexpmonth", expmonth)
            op.put("cardexpyear", expyear)
            op.put("cvmvalue", cvmvalue)
            op.put("cvmindicator", cvmindicator)
            ' add 'creditcard to order
            order.addPart("creditcard", op)

            ' Build 'billing'
            op.clear()
            op.put("name", bname)
            op.put("company", bcompany)
            op.put("address1", baddr1)
            op.put("address2", baddr2)
            op.put("city", bcity)
            op.put("state", bstate)
            ' Required for AVS. If not provided,
            ' transactions will downgrade.                  
            op.put("zip", bzip)
            op.put("addrnum", baddrnum)
            op.put("country", bcountry)
            op.put("phone", bphone)
            op.put("fax", bfax)
            op.put("email", bemail)
            ' add 'billing to order
            order.addPart("billing", op)

            ' Build 'shipping'
            op.clear()
            op.put("name", sname)
            op.put("address1", saddr1)
            op.put("address2", saddr2)
            op.put("city", scity)
            op.put("state", sstate)
            op.put("zip", szip)
            op.put("country", scountry)

            ' Create some parts we use to build order items
            Dim items, item, options As LinkPointTransaction.LPOrderPart
            items = LinkPointTransaction.LPOrderFactory.createOrderPart()
            item = LinkPointTransaction.LPOrderFactory.createOrderPart()
            options = LinkPointTransaction.LPOrderFactory.createOrderPart()
            '  build 'item'
            item.put("id", Request.Form("id2"))
            item.put("description", Request.Form("desc2"))
            item.put("quantity", Request.Form("qty2"))
            item.put("price", Request.Form("price2"))
            item.put("serial", Request.Form("serial2"))
            ' build item's options
            op.clear()
            op.put("name", "Color")
            op.put("value", Request.Form("Color"))
            options.addPart("option", op, 1)
            op.clear()
            op.put("name", "Size")
            op.put("value", Request.Form("Size"))
            options.addPart("option", op, 2)
            ' add 'options' to item
            item.addPart("options", options)
            ' add 'item' to 'items' collection
            items.addPart("item", item)
            ' add 'items' to order
            order.addPart("items", items)

            ' add notes       
            op.clear()
            op.put("comments", comments)
            op.put("referred", referred)
            order.addPart("notes", op)

            ' create transaction object      
            LPTxn = New LinkPointTransaction.LinkPointTxn()

            ' get outgoing XML from 'order' object
            Dim outXml As String = order.toXML()

            ' Call LPTxn
            Dim resp As String = LPTxn.send(keyfile, host, port, outXml)

            'Store transaction data on Session and redirect
            Session("outXml") = outXml
            Session("resp") = resp
            Server.Transfer("status.aspx")
        End Sub

        Private Sub AddUserExtraInfo()
            Dim UserNameTextBox As TextBox = CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName")
            Dim myDataSource As SqlDataSource = CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo")
            Dim User As MembershipUser = Membership.GetUser(UserNameTextBox.Text)
            Dim UserGUID As Object = User.ProviderUserKey

            myDataSource.InsertParameters.Add("UserID", UserGUID.ToString())
            myDataSource.Insert()
        End Sub


        Public Sub CreateWizard1_OnUserCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
            Dim userInfo As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
            '' Static flagUserCreated As Boolean = False
            If flagUserCreated = False Then
                userInfo.IsApproved = True
                Membership.UpdateUser(userInfo)
                Roles.AddUserToRole(CreateUserWizard1.UserName, "Users")
                AddUserExtraInfo()
                flagUserCreated = True
            End If
        End Sub
        'Private Sub CreateWizard1_OnCreatingUser(ByVal send As Object, ByVal e As System.Web.UI.Webcontrols.LoginCancelEventArgs) Handles CreateUserWizard1.CreatingUser
        'Server.Transfer("https://www.linkpointcentral.com/lpc/servlet/lppay")
        'End Sub

        ' Public Sub CreateWizard1_OnCreatingUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles CreateUserWizard1.CreatingUser
        'Me.GetPostBackClientEvent(Me.CreateUserWizard1.Controls().Item("LPPay"),
        'Dim aControl As System.Web.UI.WebControls.Button = CreateUserWizard1.contr


        ' Dim result$ = ClientScript.GetPostBackEventReference(Me.CreateUserWizard1.Controls().Item("LPPay"), "https://www.linkpointcentral.com/lpc/servlet/lppay")
        'Dim acontrol As System.Web.UI.WebControls.IButtonControl = Me.CreateUserWizard1.Controls().Item("LPPay")
        '   acontrol.PostBackUrl = "https://www.linkpointcentral.com/lpc/servlet/lppay"
        'End Sub

        Protected Sub fld_bcompany_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            Stop
        End Sub
    End Class

End Namespace

<%@ Page Language="VB"
MasterPageFile="~/MasterPage.master"
AutoEventWireup="false"
CodeFile="Order.aspx.vb"
Inherits="LinkPointAPI_vb.Order"
title="Create User and Order Now"
ClassName="Order"%>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <form id="form1" runat="server" method="post">
    <div>
        <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" BackColor="#FFFBD6" BorderColor="#FFDFAD" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Width="448px" OnCreatedUser="CreateWizard1_OnUserCreated">
            <WizardSteps>
                <asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server">
               
                <ContentTemplate>
                <table style="width: 446px">
                        <tr>
                            <th>Billing Information</th>
                        </tr>
                        <tr>
                            <td>Billing Company:</td>
                            <td style="width: 334px">
                                <asp:TextBox runat="server" ID="fld_bcompany" MaxLength="50" Text="Z2 marketing" OnTextChanged="fld_bcompany_TextChanged"/>
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator31" ControlToValidate="fld_bcompany"
                                     ErrorMessage="Your Company's Name is required."  />
                            </td>
                        </tr>

                        <tr>
                            <td>Billing Name</td>
                            <td style="width: 334px">
                                <asp:TextBox runat="server" ID="fld_bname" MaxLength="50"  />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator30" ControlToValidate="fld_bname" ErrorMessage="Your Name is Required." />
                                </td>
                                </tr>
                       <tr>
                            <td>Billing Address:</td>
                            <td style="width: 334px">
                                <asp:TextBox runat="server" ID="fld_baddr1" MaxLength="50" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ControlToValidate="fld_baddr1"
                                     ErrorMessage="Billing Address is required." />
                            </td>
                        </tr>
                        <tr>
                            <td>Billing City:</td>
                            <td style="width: 334px">
                                <asp:TextBox runat="server" ID="fld_bcity" MaxLength="50" Columns="15"  />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" ControlToValidate="fld_bcity"
                                     ErrorMessage="Billing City is required." />
                            </td>
                        </tr>  
                        <tr>
                            <td>Billing State:</td>
                            <td style="width: 334px">
                                <asp:TextBox runat="server" ID="fld_bstate" MaxLength="25" Columns="10" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator3" ControlToValidate="fld_bstate"
                                     ErrorMessage="Billing State is required."  />
                            </td>
                        </tr>  
                        <tr>
                            <td>Billing Zip:</td>
                            <td style="width: 334px">
                                <asp:TextBox runat="server" ID="fld_bzip" MaxLength="10" Columns="10"  />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator4" ControlToValidate="fld_bzip"
                                     ErrorMessage="Billing Zip is required." />
                            </td>
                        </tr>    
                            <tr>
                            <td>Billing Phone:</td>
                            <td style="width: 334px">
                                <asp:TextBox runat="server" ID="fld_bphone" MaxLength="50" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator32" ControlToValidate="fld_bphone"
                                     ErrorMessage="Billing Phone is required." />
                            </td>
                        </tr>            
                    </table>
                    <table>
                        <tr>
                            <th style="width: 157px">Select Your Product from the Menu Below</th>
                        </tr>
                        <tr>
                            <td style="width: 157px; height: 31px;">Product Selection:</td>
                            <td style="height: 31px">
                             <asp:DropDownList runat="server" id="fld_chargetotal" Height="69px" >
                                 <asp:ListItem Selected="True" Value="39.95">1 Month Credit Watch Subscription - $39.95</asp:ListItem>
                                 <asp:ListItem Value="99.95">3 Month Credit Watch Subscription - $99.95</asp:ListItem>
                                 <asp:ListItem Value="199.95">6 Month Credit Watch Subscription - $199.95</asp:ListItem>
                             </asp:DropDownList>
                             </td>
                        </tr>
                   </table>
                    <table>
                        <tr>
                            <th>Shipping Information</th>
                        </tr>
                        <tr>
                            <td>Shipping Address:</td>
                            <td>
                                <asp:TextBox runat="server" ID="fld_saddr1" MaxLength="50" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator5" ControlToValidate="fld_saddr1"
                                     ErrorMessage="Shipping Address is required." />
                            </td>
                        </tr>
                        <tr>
                            <td>Shipping City:</td>
                            <td>
                                <asp:TextBox runat="server" ID="fld_scity" MaxLength="50" Columns="15"/>
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator6" ControlToValidate="fld_scity"
                                     ErrorMessage="Shipping City is required." />
                            </td>
                        </tr>  
                        <tr>
                            <td>Shipping State:</td>
                            <td>
                                <asp:TextBox runat="server" ID="fld_sstate" MaxLength="25" Columns="10" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator7" ControlToValidate="fld_sstate"
                                     ErrorMessage="Shipping State is required." />
                            </td>
                        </tr>  
                        <tr>
                            <td>Shipping Zip:</td>
                            <td>
                                <asp:TextBox runat="server" ID="fld_szip" MaxLength="10" Columns="10" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator8" ControlToValidate="fld_szip"
                                ErrorMessage="Shipping Zip is required." />
                            </td>
                        </tr>              
                    </table>
                   <table style="width: 443px">
                   <tr>
                   <th style="width: 114px">Payment Information</th>
                   </tr>
                   <tr>
                   <td style="width: 114px">Credit Card Type</td>
                   <td>
                             <asp:DropDownList runat="server" id="fld_cctype" Height="69px" >
                                 <asp:ListItem Selected="True" Value="V">Visa</asp:ListItem>
                                 <asp:ListItem Value="M">Mastercard</asp:ListItem>
                                 <asp:ListItem Value="A">American Express</asp:ListItem>
                             </asp:DropDownList>

                       </td>                  
                    </tr>
                    <tr>
                    <td style="height: 42px">Credit Card Number</td>
                    <td style="height: 42px">
                    <asp:TextBox runat="server" ID="fld_cardnumber" MaxLength="16" />
                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator33" ControlToValidate="fld_cardnumber" ErrorMessage="Your Credit Card Information in Required"/>
                    </td>                
                    </tr>
                    <tr>
                    <td style="height: 42px">Expiration Date</td>
                    <td style="height: 42px">
                    <asp:TextBox runat="server" ID="fld_expmonth" Width="3" MaxLength="2"/>
                    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator34" ControlToValidate="fld_expmonth" ErrorMessage="Your 2 digit Experiation Month is required"/>
                     / <asp:TextBox runat="server" ID="fld_expyear" Width="3" MaxLength="4"/>
                     <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator15" ControlToValidate="fld_expyear" ErrorMessage="Your 4 digit Experiation Year is required"/>
                    </td>        
                    </tr>
                   </table>
                 
                    <table>
                        <tr>
                            <th>User Information</th>
                        </tr>
                        <tr>
                            <td>Username:</td>
                            <td style="width: 337px">
                                <asp:TextBox runat="server" ID="UserName" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator9" ControlToValidate="UserName"
                                    ErrorMessage="Username is required." />
                            </td>
                        </tr>
                        <tr>
                            <td>Password:</td>
                            <td style="width: 337px">
                                <asp:TextBox runat="server" ID="Password" TextMode="Password" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator10" ControlToValidate="Password"
                                    ErrorMessage="Password is required." />
                            </td>
                        </tr>
                        <tr>
                            <td>Confirm Password:</td>
                            <td style="width: 337px">
                                <asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator13" ControlToValidate="ConfirmPassword"
                                    ErrorMessage="Confirm Password is required." />
                            </td>
                        </tr>
                        <tr>
                            <td>Email:</td>
                            <td style="width: 337px">
                                <asp:TextBox runat="server" ID="Email" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator11" ControlToValidate="Email"
                                    ErrorMessage="Email is required." />
                            </td>
                        </tr>
                        <tr>
                            <td>Question:</td>
                            <td style="width: 337px">
                                <asp:TextBox runat="server" ID="Question" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator12" ControlToValidate="Question"
                                    ErrorMessage="Question is required." />
                            </td>
                        </tr>
                        <tr>
                            <td>Answer:</td>
                            <td style="width: 337px">
                                <asp:TextBox runat="server" ID="Answer" />
                                <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator14" ControlToValidate="Answer"
                                    ErrorMessage="Answer is required." />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                 <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
                                        ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."></asp:CompareValidator>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                            </td>
                        </tr>
                    </table>
                    <asp:SqlDataSource ID="InsertExtraInfo" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDB %>"
                        InsertCommand="INSERT INTO [UserOrderInfo] ([UserId], [bname], [bcompany, [baddr1], [bcity], [bzip], [phone], [chargetotal], [cctype], [cardnumber] [expmonth], [expyear], [saddr1], [scity], [sstate], [szip]) VALUES (@UserId, @bname, @bcompany, @baddr1, @bcity, @bzip, @phone, @chargetotal, @cctype, @cardnumber, @expmonth, @expyear, @saddr1, @scity, @sstate, @szip)"
                        ProviderName="<%$ ConnectionStrings:ASPNETDB.ProviderName %>">
                        <InsertParameters>
                            <asp:ControlParameter Name="bname" Type="String" ControlID="BuyerName" PropertyName="Text" />
                            <asp:ControlParameter Name="bcompany" Type="String" ControlID="BuyerCompany" PropertyName="Text" />
                            <asp:ControlParameter Name="baddr1" Type="String" ControlID="baddr1" PropertyName="Text" />
                            <asp:ControlParameter Name="bcity" Type="String" ControlID="bcity" PropertyName="Text" />
                            <asp:ControlParameter Name="bstate" Type="String" ControlID="bstate" PropertyName="Text" />
                            <asp:ControlParameter Name="bzip" Type="String" ControlID="bzip" PropertyName="Text" />
                            <asp:ControlParameter Name="phone" Type="String" ControlID="phone" PropertyName="Text" />
                            <asp:ControlParameter Name="chargetotal" Type="Decimal" ControlID="chargetotal" PropertyName="Text" />
                            <asp:ControlParameter Name="cctype" Type="String" ControlID="cctype" PropertyName="Text" />
                            <asp:ControlParameter Name="cardnumber" Type="String" ControlID="cardnumber" PropertyName="Text" />
                            <asp:ControlParameter Name="expmonth" Type="String" ControlID="expmonth" PropertyName="Text" />
                            <asp:ControlParameter Name="expyear" Type="String" ControlID="expyear" PropertyName="Text" />
                            <asp:ControlParameter Name="saddr1" Type="String" ControlID="saddr1" PropertyName="Text" />
                            <asp:ControlParameter Name="scity" Type="String" ControlID="scity" PropertyName="Text" />
                            <asp:ControlParameter Name="sstate" Type="String" ControlID="sstate" PropertyName="Text" />
                            <asp:ControlParameter Name="szip" Type="String" ControlID="szip" PropertyName="Text" />
                           
                        </InsertParameters>
                       
                    </asp:SqlDataSource>
                   
                </ContentTemplate>
                </asp:CreateUserWizardStep>
                <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
                    <ContentTemplate>
                        <table border="0" style="font-size: 100%; width: 448px; font-family: Verdana; background-color: #fffbd6">
                            <tr>
                                <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #990000">
                                    Complete</td>
                            </tr>
                            <tr>
                                <td>
                                    Your account has been successfully created.</td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2">
                                    <asp:Button ID="ContinueButton" runat="server" BackColor="White" BorderColor="#CC9966"
                                        BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue"
                                        Font-Names="Verdana" ForeColor="#990000" Text="Continue" ValidationGroup="CreateUserWizard1" />
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:CompleteWizardStep>
            </WizardSteps>
            <NavigationButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#990000" />
            <HeaderStyle BackColor="#FFCC66" BorderColor="#FFFBD6" BorderStyle="Solid" BorderWidth="2px" Font-Bold="True" Font-Size="0.9em" ForeColor="#333333" HorizontalAlign="Center" />
            <CreateUserButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#990000" />
            <ContinueButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#990000" />
            <SideBarStyle BackColor="#990000" Font-Size="0.9em" VerticalAlign="Top" />
            <TitleTextStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <SideBarButtonStyle ForeColor="White" />
            <FinishNavigationTemplate>
                <asp:Button ID="FinishPreviousButton" runat="server" BackColor="White" BorderColor="#CC9966"
                    BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="MovePrevious"
                    Font-Names="Verdana" ForeColor="#990000" Text="Previous" />
                <asp:Button ID="FinishButton" runat="server" BackColor="White" BorderColor="#CC9966"
                    BorderStyle="Solid" BorderWidth="1px" CommandName="MoveComplete" Font-Names="Verdana"
                    ForeColor="#990000" Text="Finish" />
            </FinishNavigationTemplate>
        </asp:CreateUserWizard>
    </div>
    </form>
</asp:Content>

Thank you for all your help.. this is very important to me!
~Michael
0
JeffreyDurham
Asked:
JeffreyDurham
1 Solution
 
QPRCommented:
the quick answer to your question - I admit to not reading all that code!
In your code behind in the event handler...

dim myVar as string = txtTextboxName.text
0
 
JeffreyDurhamAuthor Commented:
Yeah, I wouldn't have posted all that except I'm not sure where the problem lies. It's like the code section isn't recognising the fields on the behind page. I'm not sure why, but when I try to do txtTextboxName.text, it errs out, as if it can't find the field. If you check the locals window you can see that fldbcompany (for example) has a value of nothing at runtime. Essentially the field doesn't exist as far as the program is concerned. This is why I can't read the value out of it which I need.

This is where I define the box (this is inside the LinkPointTxn_Page)

<asp:TextBox runat="server" ID="fld_bcompany" MaxLength="50" Text="Z2 marketing" OnTextChanged="fld_bcompany_TextChanged"/>

Here is the beginning of the order.aspx, where I try your suggestion, using the
    dim myVar as string = txtTextboxName.text

Namespace LinkPointAPI_vb
    Public Class Order
        Inherits LinkPointTxn_Page
        ''Inherits System.Web.UI.Page
        Dim flagUserCreated As Boolean = False
        'Protected fld_bcompany As System.Web.UI.WebControls.TextBox

        Public Sub FillInFormFields()
            Session.Item("bcompany") = Me.fld_bcompany.text  <--- ERRS OUT HERE (Says fld_bcompany=>Nothing)
        End Sub
0
 
HavaganCommented:
According to your code you've commented out the reference to fld_bcompany text box.

        'Protected fld_bcompany As System.Web.UI.WebControls.TextBox <--- commented (see the comma at char pos 1?)
        Protected fld_baddr1 As System.Web.UI.WebControls.TextBox
        Protected fld_bcity As System.Web.UI.WebControls.TextBox

Try uncommenting that line.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
JeffreyDurhamAuthor Commented:
Havagan:

I removed the comment as you recommended, now the code would be:

 Protected fld_bcompany As System.Web.UI.WebControls.TextBox

The error is still there, and it is still erring on the same line. The error message is:
'Object reference not set to an instance of an object'

):
0
 
TSmoothCommented:
The reason it doesn't recognize it is because your controls are in wizard steps of the create user wizard control. This means they are part of a template which means you cannot directly reference them like you are. What you must do is use the Wizard control's reference, access the proper step on which the control is and then use the "FindControl()" method of that wizard step to get a reference to the control.

For your code pasted, as an example of how to get a reference to the text box you mentioned:
Dim fld_bcompany As TextBox = DirectCast(CreateUserWizard1.WizardSteps(0).FindControl("fld_bcompany"), TextBox)

In the above code, since your control of interest is in the first wizard step (Index of 0), we use WizardSteps(0), and then use the find control method to find a control with id "fld_bcompany" on this wizard step.

You can then access the properties of fld_bcompany such as:
Session("bcompany") = fld_bcompany.Text

You will need to do the same kind of thing for your other controls in the wizard steps. The discussion as to why you have to access template controls like this is kind of lengthy. I suggest you look up some tutorials on the subject and you can even more specifically look up tutorials on customizing the createuser wizard.
0
 
SystemExpertCommented:
Hi,

Can you tell me when you reach @
Public Sub FillInFormFields()
            Session.Item("bcompany") = Me.fld_bcompany.text                  ' HERE
End Sub
Just set debug the code
What is the value for
fld_bcompany.text                  

also plz tell what do you mean by Stop in following code

Protected Sub fld_bcompany_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            Stop
End Sub

0
 
JeffreyDurhamAuthor Commented:
Tsmooth, I was pretty sure you were right, sounded right anyways, but when I try executing the code you recommended to me to reach the textbox:

Public Sub FillInFormFields()
            Dim anyFld As Object
            anyFld = CreateUserWizard1.WizardSteps(0).FindControl("fld_bcompany")
            Session.Item("bcompany") = anyFld.Text
            'Session.Item("bcompany") = Me.fld_bcompany.Text
        End Sub

it gives me this error:

NullReferenceException Was unhandled by User Code.
Object variable or With block variable not set.

What am I doing wrong?
~Michael
0
 
TSmoothCommented:
What line of code is giving you that error? Keep in mind that you need to cast the object to a textbox to expose the .Text property. Change your code to this:

Public Sub FillInFormFields()
            Dim anyFld As TextBox
            anyFld = DirectCast(CreateUserWizard1.WizardSteps(0).FindControl("fld_bcompany"), TextBox)
            Session.Item("bcompany") = anyFld.Text
End Sub
0
 
JeffreyDurhamAuthor Commented:
TSmooth...

I tried your solution and I was able to get it to work with a few alterations.  This is what I ended up doing...

        Public Sub FillInFormFields()
            Dim anyFld As Object
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_bcompany")
            'anyFld = CreateUserWizard1.WizardSteps(0).FindControl("fld_bcompany")
            Session.Item("bcompany") = anyFld.Text
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_bname")
            Session.Item("bname") = anyFld.Text
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_baddr1")
            Session.Item("baddr1") = anyFld.Text
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_bcity")
            Session.Item("bcity") = anyFld.Text
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_bstate")
            Session.Item("bstate") = anyFld.Text
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_bzip")
            Session.Item("bzip") = anyFld.Text
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_bphone")
            Session.Item("bphone") = anyFld.Text
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_saddr1")
            Session.Item("saddr1") = anyFld.Text
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_scity")
            Session.Item("scity") = anyFld.Text
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_sstate")
            Session.Item("sstate") = anyFld.Text
            anyFld = CreateUserWizardStep2.ContentTemplateContainer.FindControl("fld_szip")
            Session.Item("szip") = anyFld.Text

            'Session.Item("bcompany") = Me.fld_bcompany.Text
        End Sub

I appreciate your help and thank you,
Michael
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now