I am having a terrible time getting anything useful out of a listbox
on my web form.
I am populating it with the results from Postcode lookup software, and
it is showing the results fine. What I want to do is to allow the
user to click on the row that corresponds to the correct address, and
have the code behind populate the form's Address1, Address2 etc.
controls with the relevant data items.
I put the code for this into the listbox's SelectedIndexCh anged event
(nothing else came close as a candidate since the Click event doesn't
exist - thanks MS).
BUT THE EVENT IS NOT FIRING.
Yes, I have AutoPostBack and EnableViewState set to True on the
listbox. There is no binding on this form. But the event just
doesn't fire. UNLESS...
Unless I make the list box SelectionMode = Multiple, in which case the
event DOES fire. It's not much use to me a) because obviously I don't
want the user to be able to select multiple addresses, and b) because
no matter which row the user selects, the SelectedIndex is always -1.
I can see from putting a breakpoint in other controls that the
SelectedIndex property is -1 elsewhere too.
Is the listbox as clueless as it seems, or is it me?
Edward
Form and code here:
<%@ Page Language="vb" AutoEventWireup ="false"
CodeBehind="New Customer.aspx.v b" Inherits="TSR.N ewCustomer" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Custom er Details</title>
<meta content="Micros oft Visual Studio.NET 7.0"
name="GENERATOR ">
<meta content="Visual Basic 7.0" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
<LINK href="../Styles.css" type="text/css" rel="stylesheet ">
</HEAD>
<body topMargin="4" MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<TABLE cellSpacing="1" cellPadding="1" width="100%">
<TBODY>
<!-- Banner Group -->
<tr>
<td style="HEIGHT: 22px">
<TABLE class="CONTAINE R" cellSpacing="0"
cellPadding="0" width="100%">
<tr>
<td bgColor="#fffff f">
<!-- Titlebar -->
<TABLE class="TITLEBAR "
cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td class="TEXTDROP "
width="100%">&n bsp;Colt Car Company Technical Service Request
System</td>
</tr>
</TABLE>
</td>
</tr>
<tr>
<td bgColor="#fffff f">
<!-- Content Frame -->
<div id="FrameBanner ">
<TABLE cellSpacing="0"
cellPadding="0" width="100%" border="0">
<tr>
<td>
<!-- Banner
Logo -->
<TABLE
cellSpacing="0" cellPadding="0" width="100%">
<TR>
<TD
align="middle"> <IMG src="../images/LOGOCOL.gif" border="0"></TD>
<TD
align="middle"> <IMG src="../images/banner.gif" width="500"
border="0"></TD>
</TR>
</TABLE>
</td>
</tr>
<TR>
</TR>
</TABLE>
</div>
</td>
</tr>
</TABLE>
</td>
</tr>
<!-- Spacer -->
<tr>
<td style="HEIGHT: 1px" height="1"></td>
</tr>
<!-- Login -->
<tr>
<td>
<table>
<tr>
<td width="50%"></td>
<td width="100">
<TABLE class="CONTAINE R"
style="WIDTH: 762px; HEIGHT: 325px" cellSpacing="0" cellPadding="0"
width="762">
<TBODY>
<!-- Titlebar -->
<tr>
<td>
<TABLE
class="TITLEBAR " cellSpacing="0" cellPadding="0" >
<tr>
<td
style="WIDTH: 4px"><IMG id="FrameBanner Login" style="POSITION :
relative" alt="Login" src="../images/login.gif" align="left"
border="0"></td>
<td
class="TEXTDROP " style="WIDTH: 339px">New Customer</td>
</tr>
</TABLE>
</td>
</tr>
<tr>
<td>
<!-- Login
Entry -->
<div
id="FrameCriter ia">
<TABLE
class="CONTAINE R" cellSpacing="0" cellPadding="0" >
<tr>
<td bgColor="button face">
<TABLE cellSpacing="0" cellPadding="0" style="WIDTH: 778px; HEIGHT:
306px">
<TR>
<!-- Criteria Entry Controls -->
<TD align="middle">
<DIV id="BigDiv" style="FONT-SIZE: 8pt; WIDTH: 792px;
FONT-FAMILY: Verdana; POSITION: relative; HEIGHT: 367px"
ms_positioning= "GridLayout ">
<asp:textbox id="txtPostCode " style="Z-INDEX: 110;
LEFT: 69px; POSITION: absolute; TOP: 96px" runat="server" Height="19"
Width="85px" CssClass="STAND ARD"></asp:textbox>
<asp:Label id="lblInstruct ions" style="Z-INDEX: 134;
LEFT: 11px; POSITION: absolute; TOP: 12px" runat="server"
Width="761px" Height="15px" ForeColor="Red" >You MUST enter the
vehicle's VIN first, to return the current owner's details. If the
name is the same then they have changed address, and you must select
the "New Address" button. If the owner has changed, you must select
the "New Owner" button.</asp:Label>
<asp:textbox id="txtAddress2 " style="Z-INDEX: 107;
LEFT: 69px; POSITION: absolute; TOP: 218px" runat="server"
Width="534px" CssClass="STAND ARD"></asp:textbox><as p:label
id="lblFirstLin eOfAddress" style="Z-INDEX: 106; LEFT: 74px; POSITION:
absolute; TOP: 171px; TEXT-ALIGN: left" runat="server" Height="3px"
Width="521px">F irst Line of Address</asp:label>
<asp:textbox id="txtAddress1 " style="Z-INDEX: 105;
LEFT: 69px; POSITION: absolute; TOP: 189px" tabIndex="5"
runat="server" Width="534" CssClass="STAND ARD"></asp:textbox>
<asp:textbox id="txtTitle" style="Z-INDEX: 103; LEFT:
69px; POSITION: absolute; TOP: 139px" tabIndex="4" runat="server"
Width="47px" CssClass="STAND ARD"></asp:textbox>
<asp:label id="lblTelephon e" style="Z-INDEX: 104;
LEFT: 44px; POSITION: absolute; TOP: 317px" runat="server"
Height="13px" Width="12px">Te l.</asp:label>
<asp:textbox id="txtTelephon e" style="Z-INDEX: 102;
LEFT: 69px; POSITION: absolute; TOP: 311px" tabIndex="7"
runat="server" Height="21px" Width="133px"
CssClass="STAND ARD"></asp:textbox>
<asp:textbox id="txtAddress3 " style="Z-INDEX: 108;
LEFT: 69px; POSITION: absolute; TOP: 239px" runat="server"
Width="534px" CssClass="STAND ARD"></asp:textbox>
<asp:textbox id="txtAddress4 " style="Z-INDEX: 109;
LEFT: 69px; POSITION: absolute; TOP: 260px" runat="server"
Width="534px" CssClass="STAND ARD"></asp:textbox>
<asp:label id="lblPostCode " style="Z-INDEX: 111;
LEFT: 14px; POSITION: absolute; TOP: 100px" runat="server"
Height="8px" Width="48px" CssClass="STAND ARD">
Postcode</asp:label>  ;
<asp:textbox id="txtAddress5 " style="Z-INDEX: 112;
LEFT: 69px; POSITION: absolute; TOP: 282px" runat="server" Width="535"
CssClass="STAND ARD"></asp:textbox><as p:label id="lblFax"
style="Z-INDEX: 113; LEFT: 236px; POSITION: absolute; TOP: 316px"
runat="server" Height="13px" Width="12px">Fa x</asp:label><asp: textbox
id="txtFax" style="Z-INDEX: 114; LEFT: 263px; POSITION: absolute; TOP:
311px" tabIndex="7" runat="server" Height="21px" Width="133px"
CssClass="STAND ARD"></asp:textbox><as p:textbox id="txtMobile"
style="Z-INDEX: 115; LEFT: 470px; POSITION: absolute; TOP: 310px"
tabIndex="7" runat="server" Height="21px" Width="133px"
CssClass="STAND ARD"></asp:textbox><as p:label id="lblMobile"
style="Z-INDEX: 116; LEFT: 429px; POSITION: absolute; TOP: 314px"
runat="server" Height="13px"
Width="12px">Mo bile</asp:label><asp: textbox id="txtEmail"
style="Z-INDEX: 117; LEFT: 69px; POSITION: absolute; TOP: 339px"
tabIndex="7" runat="server" Height="21px" Width="535px"
CssClass="STAND ARD"></asp:textbox><as p:label id="lblEmail"
style="Z-INDEX: 118; LEFT: 26px; POSITION: absolute; TOP: 343px"
runat="server" Height="13px" Width="39px">E-mail</asp:label><asp: label
id="lblTitle" style="Z-INDEX: 119; LEFT: 38px; POSITION: absolute;
TOP: 143px" runat="server" Height="8px" Width="27px"
CssClass="STAND ARD">Title</asp:label><asp: textbox id="txtFirstNam e"
style="Z-INDEX: 120; LEFT: 211px; POSITION: absolute; TOP: 139px"
tabIndex="4" runat="server" Width="155"
CssClass="STAND ARD"></asp:textbox><as p:label id="lblFirstNam e"
style="Z-INDEX: 121; LEFT: 143px; POSITION: absolute; TOP: 144px"
runat="server" Height="8px" Width="62px" CssClass="STAND ARD">First
Name</asp:label><asp: label id="lblSurname " style="Z-INDEX: 122; LEFT:
393px; POSITION: absolute; TOP: 144px" runat="server" Height="8px"
Width="53px" CssClass="STAND ARD">Surname</asp:label><asp: textbox
id="txtSurname " style="Z-INDEX: 123; LEFT: 446px; POSITION: absolute;
TOP: 139px" tabIndex="4" runat="server" Width="155px"
CssClass="STAND ARD"></asp:textbox><IN PUT id="txtCustomer ID"
style="Z-INDEX: 124; LEFT: 16px; WIDTH: 5px; POSITION: absolute; TOP:
107px; HEIGHT: 4px" type="hidden" size="1" name="txtCustom erID"
runat="server">
<INPUT id="txtAddressI D" style="Z-INDEX: 125; LEFT:
16px; WIDTH: 1px; POSITION: absolute; TOP: 138px; HEIGHT: 2px"
type="hidden" size="1" name="txtAddres sID" runat="server">
<asp:button id="cmdOk" style="Z-INDEX: 101; LEFT:
680px; POSITION: absolute; TOP: 98px" accessKey="l" tabIndex="2"
runat="server" Height="22px" Width="90px" CssClass="BUTTO N" Text="Ok"
Font-Names="Verdana" Font-Size="8pt"></asp:button><asp :textbox
id="TextBox1" style="Z-INDEX: 126; LEFT: 19px; POSITION: absolute;
TOP: 124px" runat="server" Height="2px"
Width="601px"></asp:textbox><as p:imagebutton id="cmdGetAddre ss"
style="Z-INDEX: 127; LEFT: 168px; POSITION: absolute; TOP: 96px"
runat="server" Height="21px" Width="93px"
ImageUrl="../images/getaddress.gif" ToolTip="Press here to validate
the Postcode" CausesValidatio n="False"></asp:imagebutton >
<asp:RequiredFi eldValidator
id="RequiredFie ldValidator1" style="Z-INDEX: 128; LEFT: 154px;
POSITION: absolute; TOP: 103px" runat="server" Width="11px"
Height="11px" ToolTip="Postco de required"
ControlToValida te="txtPostCode " ErrorMessage="P ostcode required">
<IMG src='../images/invalid.gif'
border='0'></asp:RequiredFie ldValidator>
<asp:RequiredFi eldValidator
id="RequiredFie ldValidator2" style="Z-INDEX: 129; LEFT: 119px;
POSITION: absolute; TOP: 146px" runat="server" Width="11px"
Height="11px" ToolTip="Title required" ControlToValida te="txtTitle"
ErrorMessage="T itle required">
<IMG src='../images/invalid.gif'
border='0'></asp:RequiredFie ldValidator>
<asp:RequiredFi eldValidator
id="RequiredFie ldValidator3" style="Z-INDEX: 130; LEFT: 371px;
POSITION: absolute; TOP: 144px" runat="server" Width="11px"
Height="11px" ToolTip="First name required"
ControlToValida te="txtFirstNam e" ErrorMessage="F irst name required">
<IMG src='../images/invalid.gif'
border='0'></asp:RequiredFie ldValidator>
<asp:RequiredFi eldValidator
id="RequiredFie ldValidator4" style="Z-INDEX: 131; LEFT: 605px;
POSITION: absolute; TOP: 145px" runat="server" Width="11px"
Height="11px" ToolTip="Surnam e required"
ControlToValida te="txtSurname " ErrorMessage="S urname required">
<IMG src='../images/invalid.gif'
border='0'></asp:RequiredFie ldValidator>
<asp:RequiredFi eldValidator
id="RequiredFie ldValidator5" style="Z-INDEX: 132; LEFT: 607px;
POSITION: absolute; TOP: 195px" runat="server" Width="11px"
Height="11px" ToolTip="First line of address required"
ControlToValida te="txtAddress1 " ErrorMessage="F irst line of address
required">
<IMG src='../images/invalid.gif'
border='0'></asp:RequiredFie ldValidator>
<asp:Validation Summary id="ValidationS ummary1"
style="Z-INDEX: 133; LEFT: 628px; POSITION: absolute; TOP: 134px"
runat="server" Width="150px" Height="231px"> </asp:ValidationS ummary>
<asp:label id="lblVIN" style="Z-INDEX: 135; LEFT:
42px; POSITION: absolute; TOP: 56px" runat="server"
CssClass="STAND ARD" Width="24px" Height="8px"> VIN</asp:label>
<asp:textbox id="txtVIN" style="Z-INDEX: 136; LEFT:
70px; POSITION: absolute; TOP: 52px" runat="server"
CssClass="STAND ARD" Width="128px" Height="19"></asp:textbox>
<asp:imagebutto n id="cmdGetVIN" style="Z-INDEX: 137;
LEFT: 201px; POSITION: absolute; TOP: 48px" runat="server"
Width="90px" Height="28px" CausesValidatio n="False"
ImageUrl="../images/vin.gif"></asp:imagebutton >
<asp:RadioButto nList id="grpChangeTy pe"
style="Z-INDEX: 138; LEFT: 341px; POSITION: absolute; TOP: 91px"
runat="server" CssClass="STAND ARD" Width="238px" Height="19px"
RepeatDirection ="Horizontal ">
<asp:ListItem Value="0">New Owner</asp:ListItem>
<asp:ListItem Value="1">New
Address</asp:ListItem>
</asp:RadioButton List>
<asp:textbox id="Textbox2" style="Z-INDEX: 139; LEFT:
19px; POSITION: absolute; TOP: 81px" runat="server" Width="746px"
Height="2px"></asp:textbox>
<asp:textbox id="txtDetails " style="Z-INDEX: 140;
LEFT: 358px; POSITION: absolute; TOP: 52px" runat="server"
CssClass="STAND ARD" Width="407px" Height="19"></asp:textbox>
<asp:label id="lblDetails " style="Z-INDEX: 141; LEFT:
311px; POSITION: absolute; TOP: 56px" runat="server"
CssClass="STAND ARD" Width="24px" Height="8px">De tails</asp:label>
<asp:ListBox id="lstAddresse s" style="Z-INDEX: 142;
LEFT: 69px; POSITION: absolute; TOP: 188px" runat="server"
Width="535px" Height="170px" AutoPostBack="T rue" Visible="False"
SelectionMode=" Multiple"></asp:ListBox>
<asp:button id="cmdBackUp" style="Z-INDEX: 143; LEFT:
512px; POSITION: absolute; TOP: 164px" accessKey="l" tabIndex="2"
runat="server" CssClass="BUTTO N" Width="90px" Height="22px"
Font-Size="8pt" Font-Names="Verdana" Text="Back
Up"></asp:button></DIV>
</TD>
<!-- Criteria Buttons --></TR>
</TABLE>
</td>
</tr>
</TABLE>
</div>
</td>
</tr>
</TBODY>
</TABLE>
</td>
<td width="100%"></td>
</tr>
</table>
</td>
</tr>
</TBODY>
</TABLE>
<table style="WIDTH: 762px; HEIGHT: 110px" width="784">
<tr>
<td style="HEIGHT: 8px"><BR>
</td>
</tr>
<tr>
<td class="TEXT" align="middle">
<P><SMALL></SMALL> </P>
<P><SMALL>Pre ss <STRONG>F11</STRONG> to view
full-screen
<BR>
Ensure Cookies, Javascript and ActiveX
controls are enabled
<br>
<br>
All contents © Spitalga te Dealer
Services Ltd. 2003
<BR>
</SMALL>
</P>
</td>
</tr>
</table>
</form>
</body>
</HTML>
'************** *************** *************** *************** *************** *
'* Object Name: NewCustomer.vb
'************** *************** *************** *************** *************** *
'* COPYRIGHT (C) 2003, Tech OP Ltd, UK
'*
'* PROJECT: CCC - TSR System
'************** *************** *************** *************** *************** *
'*
'* PURPOSE:
'* This class contains code behind for the New Customer form
'*
'************** *************** *************** *************** *************** *
'* HISTORY
'* VERSION DATE INITIALS CHANGES
'* 1.0 03/11/03 TO Initial Version
'************** *************** *************** *************** *************** *
Imports System.Text
Imports System.IO
Imports System.Data.Sql Client
Imports TechOP.Applicat ionBlocks.Data
Public Class NewCustomer
Inherits System.Web.UI.P age
Protected WithEvents lblTelephone As
System.Web.UI.W ebControls.Labe l
Protected WithEvents RegularExpressi onValidator1 As
System.Web.UI.W ebControls.Regu larExpressionVa lidator
Protected WithEvents txtTelephone As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtPostCode As
System.Web.UI.W ebControls.Text Box
Protected WithEvents lblPostCode As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAddress2 As
System.Web.UI.W ebControls.Text Box
Protected WithEvents lblFirstLineOfA ddress As
System.Web.UI.W ebControls.Labe l
Protected WithEvents txtAddress1 As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtMileage As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAddress5 As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAddress3 As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAddress4 As
System.Web.UI.W ebControls.Text Box
Protected WithEvents lblFax As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtFax As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtMobile As System.Web.UI.W ebControls.Text Box
Protected WithEvents lblMobile As System.Web.UI.W ebControls.Labe l
Protected WithEvents cmdNew As System.Web.UI.W ebControls.Butt on
Protected WithEvents txtTitle As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtEmail As System.Web.UI.W ebControls.Text Box
Protected WithEvents lblEmail As System.Web.UI.W ebControls.Labe l
Protected WithEvents lblTitle As System.Web.UI.W ebControls.Labe l
Protected WithEvents lblFirstName As
System.Web.UI.W ebControls.Labe l
Protected WithEvents txtFirstName As
System.Web.UI.W ebControls.Text Box
Protected WithEvents lblSurname As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtSurname As
System.Web.UI.W ebControls.Text Box
Protected WithEvents txtCustomerID As
System.Web.UI.H tmlControls.Htm lInputHidden
Protected WithEvents TextBox1 As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtAddressID As
System.Web.UI.H tmlControls.Htm lInputHidden
Protected WithEvents RequiredFieldVa lidator1 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents RequiredFieldVa lidator2 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents RequiredFieldVa lidator3 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents RequiredFieldVa lidator4 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents RequiredFieldVa lidator5 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents ValidationSumma ry1 As
System.Web.UI.W ebControls.Vali dationSummary
Protected WithEvents lblInstructions As
System.Web.UI.W ebControls.Labe l
Protected WithEvents lblVIN As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtVIN As System.Web.UI.W ebControls.Text Box
Protected WithEvents cmdGetVIN As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents grpChangeType As
System.Web.UI.W ebControls.Radi oButtonList
Protected WithEvents Textbox2 As System.Web.UI.W ebControls.Text Box
Protected WithEvents txtDetails As
System.Web.UI.W ebControls.Text Box
Protected WithEvents lblDetails As System.Web.UI.W ebControls.Labe l
Protected WithEvents cmdOk As System.Web.UI.W ebControls.Butt on
Protected WithEvents cmdGetAddress As
System.Web.UI.W ebControls.Imag eButton
Protected WithEvents lstAddresses As
System.Web.UI.W ebControls.List Box
Protected WithEvents cmdBackUp As System.Web.UI.W ebControls.Butt on
Private mblnVehicleFoun d As Boolean = False
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region
Public mRecord As TSRRecord
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
' Determine if postback
If (Not (Page.IsPostBac k)) Then
' Get values from calling form
Call cbfGetCallingVa lues()
HttpContext.Cur rent.Session("B adVIN") = ""
'If ((CType(HttpCon text.Current.Se ssion("PostCode "),
String)).Length > 0) Then
' Me.txtPostCode. Text =
CType(HttpConte xt.Current.Sess ion("PostCode") , String)
'End If
End If
End Sub
Private Sub cbfGetCallingVa lues()
' Get next form calling stack item
Dim CallingValues As FormCalling_Det ails =
Get_FormCalling _Values(PageNav igation.PageID. ItemTSRs)
If (Not (IsNothing(Call ingValues.ID2)) ) Then
Me.CompanyID = CallingValues.I D2
Me.CallerForm = CallingValues.S ourcePage
If (Not (IsNothing(Call ingValues.ID1)) ) Then
Me.RecordID = CallingValues.I D1
Else
Me.RecordID = ""
End If
End If
End Sub
Private Sub cmdSave_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s)
' Attempt to save contact - move to calling form
If (cbfSaveCustome r()) Then
' Remove calling details from stack
Remove_FormCall ing_StackItem()
' Redirect to calling form
PageNavigation. MovetoPage(Me.C allerForm)
End If
End Sub
Private Function cbfSaveCustomer () As Boolean
Dim blnReturn As Boolean = False
'TODO - check if customer details updated (existing customer new
address) or new customer
' Ensure page validated
Me.Page.Validat e()
' Store new values
Dim params(14) As SqlClient.SqlPa rameter
Dim intCount As Integer = 0
Dim intCustomerID As Integer = 0
params(intCount ) = New SqlClient.SqlPa rameter("@Custo merID",
intCustomerID)
params(intCount ).Direction = ParameterDirect ion.InputOutput
params(Incremen tIndex(intCount )) = New SqlParameter("@ Title",
Me.txtTitle.Tex t)
params(Incremen tIndex(intCount )) = New
SqlParameter("@ FirstName", Me.txtFirstName .Text)
params(Incremen tIndex(intCount )) = New SqlParameter("@ Surname",
Me.txtSurname.T ext)
params(Incremen tIndex(intCount )) = New SqlParameter("@ Email",
Me.txtEmail.Tex t)
params(Incremen tIndex(intCount )) = New SqlParameter("@ Address1",
Me.txtAddress1. Text)
params(Incremen tIndex(intCount )) = New SqlParameter("@ Address2",
Me.txtAddress2. Text)
params(Incremen tIndex(intCount )) = New SqlParameter("@ Address3",
Me.txtAddress3. Text)
params(Incremen tIndex(intCount )) = New SqlParameter("@ Address4",
Me.txtAddress4. Text)
params(Incremen tIndex(intCount )) = New SqlParameter("@ Address5",
Me.txtAddress5. Text)
params(Incremen tIndex(intCount )) = New SqlParameter("@ Postcode",
Me.txtPostCode. Text)
params(Incremen tIndex(intCount )) = New
SqlParameter("@ DaytimeTel", Me.txtTelephone .Text)
params(Incremen tIndex(intCount )) = New SqlParameter("@ Fax",
Me.txtFax.Text)
params(Incremen tIndex(intCount )) = New SqlParameter("@ Mobile",
Me.txtMobile.Te xt)
params(Incremen tIndex(intCount )) = New SqlParameter("@ User",
LogonUser.UserI D)
Dim intReturn As Integer =
SqlHelper.Execu teNonQuery(Conf igSettings.Syst emConnectionStr ing,
CommandType.Sto redProcedure, "stpAddNewCusto merFromTSR", params)
If (intReturn > 0) Then
intCustomerID = params(0).Value
LogonUser.Custo merID = intCustomerID
blnReturn = True
Else
blnReturn = False
End If
If (Not (blnReturn)) Then
' Display failure message to client
Call DisplayClientMe ssage("Failure" , "Save failed")
End If
' Return save outcome
Return blnReturn
End Function
' Store current recordID in viewstate
Property RecordID() As String
Get
Return CType(ViewState ("RecordID") , String)
End Get
Set(ByVal Value As String)
ViewState("Reco rdID") = Value
End Set
End Property
' Store current CompanyID in viewstate
Property CompanyID() As String
Get
Return CType(ViewState ("CompanyID" ), String)
End Get
Set(ByVal Value As String)
ViewState("Comp anyID") = Value
End Set
End Property
' Store current callerform in viewstate
Property CallerForm() As PageID
Get
Return CType(ViewState ("CallerForm "), PageID)
End Get
Set(ByVal Value As PageID)
ViewState("Call erForm") = Value
End Set
End Property
Private Sub DisplayClientMe ssage(ByVal pstrID As String, ByVal
pstrMessage As String, Optional ByVal pfClose As Boolean = False)
Page.RegisterSt artupScript(pst rID, "<script
language=javasc ript>alert('" & pstrMessage & "');" + _
IIf(pfClose,
"history.back() ;", "") + "</script>")
Console.Write(" here")
End Sub
Private Sub cmdCancel_Click (ByVal sender As System.Object, ByVal e
As System.EventArg s)
' Remove calling details from stack
Remove_FormCall ing_StackItem()
' Redirect to calling form
PageNavigation. MovetoPage(CTyp e(Me.CallerForm , PageID))
End Sub
Private Sub cmdGetAddress_C lick(ByVal sender As Object, ByVal e As
System.Web.UI.I mageClickEventA rgs) Handles cmdGetAddress.C lick
' Get the customer address from the QAS software and populate
appropriate fields
'Dim cQAddress As New QuickAddressCla ss()
Dim colAddresses As Collection
Dim blnSingleAddres s As Boolean
Dim intCount As Integer
Call QuickAddressCla ss.OpenQuickAdd ress()
blnSingleAddres s =
QuickAddressCla ss.StartQuickAd dressSearch(Me. txtPostCode.Tex t,
colAddresses)
If blnSingleAddres s Then
'Call cbfPopulateFiel ds(colAddresses )
Else
Me.lstAddresses .Visible = True
Me.lblTelephone .Visible = False
Me.lblEmail.Vis ible = False
Me.lblFirstLine OfAddress.Text = "Please select the correct
address from the list"
If (colAddresses.C ount > 0) Then
lstAddresses.It ems.Clear()
For intCount = 1 To colAddresses.Co unt
lstAddresses.It ems.Add(colAddr esses.Item(intC ount))
Next
End If
End If
End Sub
Private Sub cmdOk_Click(ByV al sender As System.Object, ByVal e As
System.EventArg s) Handles cmdOk.Click
'TODO If the user has entered "New Owner" there is no need to
search for existing Contact.
If (cbfValidateFor m()) Then
If (cbfSaveCustome r()) Then
If (mblnVehicleFou nd) Then
'TODO Create Contact and populate the New TSR form
Else
PageNavigation. MovetoPage(Page Navigation.Page ID.NewVehicle)
End If
End If
End If
End Sub
Private Function cbfValidateForm () As Boolean
'Dim strMessage As String = ""
'If (Me.txtAddress1 .Text.Length <= 0) Then
' strMessage &= "First line of address" & vbCrLf
'End If
'If (Me.txtSurname. Text.Length <= 0) Then
' strMessage &= "Surname" & vbCrLf
'End If
'If (Me.txtPostCode .Text.Length <= 0) Then
' strMessage &= "Postcode" & vbCrLf
'End If
'If (strMessage.Len gth = 0) Then
Return True
'Else
' strMessage = "You must complete the following fields before
continuing:" & vbCrLf & strMessage
' DisplayClientMe ssage("message" , strMessage)
' Return False
'End If
End Function
Private Sub cmdGetVIN_Click (ByVal sender As System.Object, ByVal e
As System.Web.UI.I mageClickEventA rgs) Handles cmdGetVIN.Click
' Get the vehicle ID for this VIN, check the current owner and
populate the form.
Dim strSQL As String
Dim objDR As SqlDataReader
Dim blnHasRows As Boolean = False
' Find out if the VIN exists - if is does, then display the
results. If not, then ask user they are sure of the number
Try
' Attempt to get user attributes
strSQL = "SELECT tblVehicles.fld VehicleID,
tblVehicles.fld CustomerID, tblVehicleModel s.fldVehicleMod el,
tblVehicleVaria nts.tblVehicleV ariant, " _
& "tblVehicles.fl dRegistrationNu mber FROM tblVehicles INNER
JOIN tblVehicleModel s ON " _
& "tblVehicles.fl dVehicleModelID =
tblVehicleModel s.fldVehicleMod elID INNER JOIN tblVehicleVaria nts ON "
_
& "tblVehicles.fl dVehicleVariant ID =
tblVehicleVaria nts.fldVehicleV ariantID " _
& "WHERE (tblVehicles.fl dVIN = '" & Me.txtVIN.Text & "')"
objDR = SqlHelper.Execu teReader(Config Settings.System ConnectionStrin g,
CommandType.Tex t, strSQL)
' If there is data then populate the form and lock the
controls, otherwise, clear the form (except for the VIN) for new data
While objDR.Read()
' Success
blnHasRows = True
mblnVehicleFoun d = True
LogonUser.Vehic leID = objDR("fldVehic leID")
Dim intCustomerID As Integer =
CType(objDR("fl dCustomerID"), Integer)
Me.txtDetails.T ext = objDR("fldVehic leModel") & ", " &
objDR("tblVehic leVariant") & ", " & objDR("fldRegis trationNumber")
' Close reader
objDR.Close()
strSQL = "SELECT tblCustomers.fl dTitle,
tblCustomers.fl dFirstName, tblCustomers.fl dSurname,
tblCustomers.fl dCustomerID, " _
& "tblCustomers.f ldEmailAddress,
tblAddresses.fl dDaytimeTel, tblAddresses.fl dMobileTel,
tblAddresses.fl dFax " _
& "FROM tblCustomers INNER JOIN tblAddresses ON
tblCustomers.fl dCustomerID = tblAddresses.fl dCustomerID " _
& "WHERE ((tblAddresses. fldPrimaryAddre ss = - 1) AND
(tblCustomers.f ldCustomerID = " & intCustomerID & "))"
objDR = SqlHelper.Execu teReader(Config Settings.System ConnectionStrin g,
CommandType.Tex t, strSQL)
While objDR.Read
Me.txtEmail.Tex t = CType(objDR("fl dEmailAddress") ,
String)
Me.txtTitle.Tex t = CType(objDR("fl dTitle"), String)
Me.txtFirstName .Text = CType(objDR("fl dFirstName"),
String)
Me.txtSurname.T ext = CType(objDR("fl dSurname"), String)
Me.txtTelephone .Text = CType(objDR("fl dDaytimeTel"),
String)
Me.txtMobile.Te xt = CType(objDR("fl dMobileTel"),
String)
Me.txtFax.Text = CType(objDR("fl dFax"), String)
End While
End While
' Close reader
objDR.Close()
If (Not (blnHasRows)) Then
mblnVehicleFoun d = False
' VIN not known to the system. If it is the first time
this session that the user has entered this value, then put up a
' message telling them that the VIN is not known and to
check and repress the button.
' If the user is re-entering the same unknown VIN then
bypass message and allow them to add it.
If ((CType(HttpCon text.Current.Se ssion("BadVIN") , String)
<> Me.txtVIN.Text) ) Then
DisplayClientMe ssage("VIN", "This VIN is not known to
the system. Please check that it is correct and press the button
again")
Else
DisplayClientMe ssage("VIN", "This VIN is not known to
the system. Enter the customer details and press OK. You will be
returned to the " _
& "Contact Wizard from where you can enter the details
of the new vehicle")
End If
HttpContext.Cur rent.Session("B adVIN") = Me.txtVIN.Text
End If
Catch ex As Exception
Finally
objDR.Close()
End Try
End Sub
Private Sub Page_Unload(ByV al sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Unload
Try
Call QuickAddressCla ss.CloseQuickAd dress()
Catch
End Try
End Sub
Private Sub lstAddresses_Se lectedIndexChan ged(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
lstAddresses.Se lectedIndexChan ged
Dim intValue As Integer
Dim colAddressed As New Collection()
Dim intCount As Integer
'lblError.Text = ""
' Get the selected items index, this is used to determine the
whether the item has sub items
' or retrieves the address itself.
intValue = lstAddresses.Se lectedIndex
Try
' Does the selected Item have subitems?
If (QuickAddressCl ass.AddressSubI tems(intValue,
colAddressed)) Then
' Yes it does, use the collection returned to populate the
your control
If (colAddressed.C ount > 0) Then
lstAddresses.It ems.Clear()
For intCount = 1 To colAddressed.Co unt
lstAddresses.It ems.Add(colAddr essed.Item(intC ount))
Next
End If
cmdBackUp.Enabl ed = True
cmdOk.Enabled = False
Else
' Get the item selected and populate the address text
boxes
QuickAddressCla ss.GetAddress(i ntValue, colAddressed)
' This always returns a collection of 5 strings, the last
one being the postcode.
'mcolSelectedAd dress = colAddressed
cmdOk.Enabled = True
End If
Catch ex As Exception
'lblError.Text = ex.Message
End Try
End Sub
End Class