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
by: QPRPosted on 2007-08-09 at 16:00:14ID: 19666682
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