By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,558 Members | 1,607 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,558 IT Pros & Developers. It's quick & easy.

Listbox SelectedIndexChanged not firing (Autopostback = True)

P: n/a
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 SelectedIndexChanged 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="NewCustomer.aspx.vb" Inherits="TSR.NewCustomer" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Customer Details</title>
<meta content="Microsoft Visual Studio.NET 7.0"
name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<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="CONTAINER" cellSpacing="0"
cellPadding="0" width="100%">
<tr>
<td bgColor="#ffffff">
<!-- Titlebar -->
<TABLE class="TITLEBAR"
cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td class="TEXTDROP"
width="100%">&nbsp;Colt Car Company Technical Service Request
System</td>
</tr>
</TABLE>
</td>
</tr>
<tr>
<td bgColor="#ffffff">
<!-- 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="CONTAINER"
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="FrameBannerLogin" 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="FrameCriteria">
<TABLE
class="CONTAINER" cellSpacing="0" cellPadding="0">
<tr>

<td bgColor="buttonface">

<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="STANDARD"></asp:textbox>

<asp:Label id="lblInstructions" 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="STANDARD"></asp:textbox><asp:label
id="lblFirstLineOfAddress" style="Z-INDEX: 106; LEFT: 74px; POSITION:
absolute; TOP: 171px; TEXT-ALIGN: left" runat="server" Height="3px"
Width="521px">First 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="STANDARD"></asp:textbox>

<asp:textbox id="txtTitle" style="Z-INDEX: 103; LEFT:
69px; POSITION: absolute; TOP: 139px" tabIndex="4" runat="server"
Width="47px" CssClass="STANDARD"></asp:textbox>

<asp:label id="lblTelephone" style="Z-INDEX: 104;
LEFT: 44px; POSITION: absolute; TOP: 317px" runat="server"
Height="13px" Width="12px">Tel.</asp:label>

<asp:textbox id="txtTelephone" style="Z-INDEX: 102;
LEFT: 69px; POSITION: absolute; TOP: 311px" tabIndex="7"
runat="server" Height="21px" Width="133px"
CssClass="STANDARD"></asp:textbox>

<asp:textbox id="txtAddress3" style="Z-INDEX: 108;
LEFT: 69px; POSITION: absolute; TOP: 239px" runat="server"
Width="534px" CssClass="STANDARD"></asp:textbox>

<asp:textbox id="txtAddress4" style="Z-INDEX: 109;
LEFT: 69px; POSITION: absolute; TOP: 260px" runat="server"
Width="534px" CssClass="STANDARD"></asp:textbox>

<asp:label id="lblPostCode" style="Z-INDEX: 111;
LEFT: 14px; POSITION: absolute; TOP: 100px" runat="server"
Height="8px" Width="48px" CssClass="STANDARD">
Postcode</asp:label>&nbsp;

<asp:textbox id="txtAddress5" style="Z-INDEX: 112;
LEFT: 69px; POSITION: absolute; TOP: 282px" runat="server" Width="535"
CssClass="STANDARD"></asp:textbox><asp:label id="lblFax"
style="Z-INDEX: 113; LEFT: 236px; POSITION: absolute; TOP: 316px"
runat="server" Height="13px" Width="12px">Fax</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="STANDARD"></asp:textbox><asp:textbox id="txtMobile"
style="Z-INDEX: 115; LEFT: 470px; POSITION: absolute; TOP: 310px"
tabIndex="7" runat="server" Height="21px" Width="133px"
CssClass="STANDARD"></asp:textbox><asp:label id="lblMobile"
style="Z-INDEX: 116; LEFT: 429px; POSITION: absolute; TOP: 314px"
runat="server" Height="13px"
Width="12px">Mobile</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="STANDARD"></asp:textbox><asp: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="STANDARD">Title</asp:label><asp:textbox id="txtFirstName"
style="Z-INDEX: 120; LEFT: 211px; POSITION: absolute; TOP: 139px"
tabIndex="4" runat="server" Width="155"
CssClass="STANDARD"></asp:textbox><asp:label id="lblFirstName"
style="Z-INDEX: 121; LEFT: 143px; POSITION: absolute; TOP: 144px"
runat="server" Height="8px" Width="62px" CssClass="STANDARD">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="STANDARD">Surname</asp:label><asp:textbox
id="txtSurname" style="Z-INDEX: 123; LEFT: 446px; POSITION: absolute;
TOP: 139px" tabIndex="4" runat="server" Width="155px"
CssClass="STANDARD"></asp:textbox><INPUT id="txtCustomerID"
style="Z-INDEX: 124; LEFT: 16px; WIDTH: 5px; POSITION: absolute; TOP:
107px; HEIGHT: 4px" type="hidden" size="1" name="txtCustomerID"
runat="server">

<INPUT id="txtAddressID" style="Z-INDEX: 125; LEFT:
16px; WIDTH: 1px; POSITION: absolute; TOP: 138px; HEIGHT: 2px"
type="hidden" size="1" name="txtAddressID" 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="BUTTON" 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><asp:imagebutton id="cmdGetAddress"
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" CausesValidation="False"></asp:imagebutton>

<asp:RequiredFieldValidator
id="RequiredFieldValidator1" style="Z-INDEX: 128; LEFT: 154px;
POSITION: absolute; TOP: 103px" runat="server" Width="11px"
Height="11px" ToolTip="Postcode required"
ControlToValidate="txtPostCode" ErrorMessage="Postcode required">

<IMG src='../images/invalid.gif'
border='0'></asp:RequiredFieldValidator>

<asp:RequiredFieldValidator
id="RequiredFieldValidator2" style="Z-INDEX: 129; LEFT: 119px;
POSITION: absolute; TOP: 146px" runat="server" Width="11px"
Height="11px" ToolTip="Title required" ControlToValidate="txtTitle"
ErrorMessage="Title required">

<IMG src='../images/invalid.gif'
border='0'></asp:RequiredFieldValidator>

<asp:RequiredFieldValidator
id="RequiredFieldValidator3" style="Z-INDEX: 130; LEFT: 371px;
POSITION: absolute; TOP: 144px" runat="server" Width="11px"
Height="11px" ToolTip="First name required"
ControlToValidate="txtFirstName" ErrorMessage="First name required">

<IMG src='../images/invalid.gif'
border='0'></asp:RequiredFieldValidator>

<asp:RequiredFieldValidator
id="RequiredFieldValidator4" style="Z-INDEX: 131; LEFT: 605px;
POSITION: absolute; TOP: 145px" runat="server" Width="11px"
Height="11px" ToolTip="Surname required"
ControlToValidate="txtSurname" ErrorMessage="Surname required">

<IMG src='../images/invalid.gif'
border='0'></asp:RequiredFieldValidator>

<asp:RequiredFieldValidator
id="RequiredFieldValidator5" style="Z-INDEX: 132; LEFT: 607px;
POSITION: absolute; TOP: 195px" runat="server" Width="11px"
Height="11px" ToolTip="First line of address required"
ControlToValidate="txtAddress1" ErrorMessage="First line of address
required">

<IMG src='../images/invalid.gif'
border='0'></asp:RequiredFieldValidator>

<asp:ValidationSummary id="ValidationSummary1"
style="Z-INDEX: 133; LEFT: 628px; POSITION: absolute; TOP: 134px"
runat="server" Width="150px" Height="231px"></asp:ValidationSummary>

<asp:label id="lblVIN" style="Z-INDEX: 135; LEFT:
42px; POSITION: absolute; TOP: 56px" runat="server"
CssClass="STANDARD" Width="24px" Height="8px"> VIN</asp:label>

<asp:textbox id="txtVIN" style="Z-INDEX: 136; LEFT:
70px; POSITION: absolute; TOP: 52px" runat="server"
CssClass="STANDARD" Width="128px" Height="19"></asp:textbox>

<asp:imagebutton id="cmdGetVIN" style="Z-INDEX: 137;
LEFT: 201px; POSITION: absolute; TOP: 48px" runat="server"
Width="90px" Height="28px" CausesValidation="False"
ImageUrl="../images/vin.gif"></asp:imagebutton>

<asp:RadioButtonList id="grpChangeType"
style="Z-INDEX: 138; LEFT: 341px; POSITION: absolute; TOP: 91px"
runat="server" CssClass="STANDARD" Width="238px" Height="19px"
RepeatDirection="Horizontal">

<asp:ListItem Value="0">New Owner</asp:ListItem>

<asp:ListItem Value="1">New
Address</asp:ListItem>

</asp:RadioButtonList>

<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="STANDARD" Width="407px" Height="19"></asp:textbox>

<asp:label id="lblDetails" style="Z-INDEX: 141; LEFT:
311px; POSITION: absolute; TOP: 56px" runat="server"
CssClass="STANDARD" Width="24px" Height="8px">Details</asp:label>

<asp:ListBox id="lstAddresses" style="Z-INDEX: 142;
LEFT: 69px; POSITION: absolute; TOP: 188px" runat="server"
Width="535px" Height="170px" AutoPostBack="True" 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="BUTTON" 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>&nbsp;</P>
<P><SMALL>Press <STRONG>F11</STRONG> to view
full-screen
<BR>
Ensure Cookies, Javascript and ActiveX
controls are enabled
<br>
<br>
All contents &nbsp;Spitalgate 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.SqlClient
Imports TechOP.ApplicationBlocks.Data

Public Class NewCustomer
Inherits System.Web.UI.Page
Protected WithEvents lblTelephone As
System.Web.UI.WebControls.Label
Protected WithEvents RegularExpressionValidator1 As
System.Web.UI.WebControls.RegularExpressionValidat or
Protected WithEvents txtTelephone As
System.Web.UI.WebControls.TextBox
Protected WithEvents txtPostCode As
System.Web.UI.WebControls.TextBox
Protected WithEvents lblPostCode As System.Web.UI.WebControls.Label
Protected WithEvents txtAddress2 As
System.Web.UI.WebControls.TextBox
Protected WithEvents lblFirstLineOfAddress As
System.Web.UI.WebControls.Label
Protected WithEvents txtAddress1 As
System.Web.UI.WebControls.TextBox
Protected WithEvents txtMileage As
System.Web.UI.WebControls.TextBox
Protected WithEvents txtAddress5 As
System.Web.UI.WebControls.TextBox
Protected WithEvents txtAddress3 As
System.Web.UI.WebControls.TextBox
Protected WithEvents txtAddress4 As
System.Web.UI.WebControls.TextBox
Protected WithEvents lblFax As System.Web.UI.WebControls.Label
Protected WithEvents txtFax As System.Web.UI.WebControls.TextBox
Protected WithEvents txtMobile As System.Web.UI.WebControls.TextBox
Protected WithEvents lblMobile As System.Web.UI.WebControls.Label
Protected WithEvents cmdNew As System.Web.UI.WebControls.Button
Protected WithEvents txtTitle As System.Web.UI.WebControls.TextBox
Protected WithEvents txtEmail As System.Web.UI.WebControls.TextBox
Protected WithEvents lblEmail As System.Web.UI.WebControls.Label
Protected WithEvents lblTitle As System.Web.UI.WebControls.Label
Protected WithEvents lblFirstName As
System.Web.UI.WebControls.Label
Protected WithEvents txtFirstName As
System.Web.UI.WebControls.TextBox
Protected WithEvents lblSurname As System.Web.UI.WebControls.Label
Protected WithEvents txtSurname As
System.Web.UI.WebControls.TextBox
Protected WithEvents txtCustomerID As
System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents txtAddressID As
System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator2 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator3 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator4 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator5 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents ValidationSummary1 As
System.Web.UI.WebControls.ValidationSummary
Protected WithEvents lblInstructions As
System.Web.UI.WebControls.Label
Protected WithEvents lblVIN As System.Web.UI.WebControls.Label
Protected WithEvents txtVIN As System.Web.UI.WebControls.TextBox
Protected WithEvents cmdGetVIN As
System.Web.UI.WebControls.ImageButton
Protected WithEvents grpChangeType As
System.Web.UI.WebControls.RadioButtonList
Protected WithEvents Textbox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents txtDetails As
System.Web.UI.WebControls.TextBox
Protected WithEvents lblDetails As System.Web.UI.WebControls.Label
Protected WithEvents cmdOk As System.Web.UI.WebControls.Button
Protected WithEvents cmdGetAddress As
System.Web.UI.WebControls.ImageButton
Protected WithEvents lstAddresses As
System.Web.UI.WebControls.ListBox
Protected WithEvents cmdBackUp As System.Web.UI.WebControls.Button

Private mblnVehicleFound As Boolean = False

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Public mRecord As TSRRecord

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

' Determine if postback
If (Not (Page.IsPostBack)) Then

' Get values from calling form
Call cbfGetCallingValues()
HttpContext.Current.Session("BadVIN") = ""
'If ((CType(HttpContext.Current.Session("PostCode"),
String)).Length > 0) Then
' Me.txtPostCode.Text =
CType(HttpContext.Current.Session("PostCode"), String)
'End If
End If

End Sub

Private Sub cbfGetCallingValues()

' Get next form calling stack item
Dim CallingValues As FormCalling_Details =
Get_FormCalling_Values(PageNavigation.PageID.ItemT SRs)
If (Not (IsNothing(CallingValues.ID2))) Then
Me.CompanyID = CallingValues.ID2
Me.CallerForm = CallingValues.SourcePage
If (Not (IsNothing(CallingValues.ID1))) Then
Me.RecordID = CallingValues.ID1
Else
Me.RecordID = ""
End If
End If

End Sub
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

' Attempt to save contact - move to calling form
If (cbfSaveCustomer()) Then

' Remove calling details from stack
Remove_FormCalling_StackItem()

' Redirect to calling form
PageNavigation.MovetoPage(Me.CallerForm)
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.Validate()

' Store new values
Dim params(14) As SqlClient.SqlParameter
Dim intCount As Integer = 0
Dim intCustomerID As Integer = 0

params(intCount) = New SqlClient.SqlParameter("@CustomerID",
intCustomerID)
params(intCount).Direction = ParameterDirection.InputOutput

params(IncrementIndex(intCount)) = New SqlParameter("@Title",
Me.txtTitle.Text)
params(IncrementIndex(intCount)) = New
SqlParameter("@FirstName", Me.txtFirstName.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@Surname",
Me.txtSurname.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@Email",
Me.txtEmail.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@Address1",
Me.txtAddress1.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@Address2",
Me.txtAddress2.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@Address3",
Me.txtAddress3.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@Address4",
Me.txtAddress4.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@Address5",
Me.txtAddress5.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@Postcode",
Me.txtPostCode.Text)
params(IncrementIndex(intCount)) = New
SqlParameter("@DaytimeTel", Me.txtTelephone.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@Fax",
Me.txtFax.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@Mobile",
Me.txtMobile.Text)
params(IncrementIndex(intCount)) = New SqlParameter("@User",
LogonUser.UserID)

Dim intReturn As Integer =
SqlHelper.ExecuteNonQuery(ConfigSettings.SystemCon nectionString,
CommandType.StoredProcedure, "stpAddNewCustomerFromTSR", params)
If (intReturn > 0) Then
intCustomerID = params(0).Value
LogonUser.CustomerID = intCustomerID
blnReturn = True
Else
blnReturn = False
End If

If (Not (blnReturn)) Then

' Display failure message to client
Call DisplayClientMessage("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("RecordID") = 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("CompanyID") = 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("CallerForm") = Value
End Set
End Property

Private Sub DisplayClientMessage(ByVal pstrID As String, ByVal
pstrMessage As String, Optional ByVal pfClose As Boolean = False)
Page.RegisterStartupScript(pstrID, "<script
language=javascript>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.EventArgs)

' Remove calling details from stack
Remove_FormCalling_StackItem()

' Redirect to calling form
PageNavigation.MovetoPage(CType(Me.CallerForm, PageID))

End Sub

Private Sub cmdGetAddress_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles cmdGetAddress.Click

' Get the customer address from the QAS software and populate
appropriate fields
'Dim cQAddress As New QuickAddressClass()
Dim colAddresses As Collection
Dim blnSingleAddress As Boolean
Dim intCount As Integer

Call QuickAddressClass.OpenQuickAddress()
blnSingleAddress =
QuickAddressClass.StartQuickAddressSearch(Me.txtPo stCode.Text,
colAddresses)
If blnSingleAddress Then
'Call cbfPopulateFields(colAddresses)
Else
Me.lstAddresses.Visible = True
Me.lblTelephone.Visible = False
Me.lblEmail.Visible = False
Me.lblFirstLineOfAddress.Text = "Please select the correct
address from the list"
If (colAddresses.Count > 0) Then
lstAddresses.Items.Clear()
For intCount = 1 To colAddresses.Count
lstAddresses.Items.Add(colAddresses.Item(intCount) )
Next
End If
End If
End Sub

Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdOk.Click

'TODO If the user has entered "New Owner" there is no need to
search for existing Contact.
If (cbfValidateForm()) Then
If (cbfSaveCustomer()) Then
If (mblnVehicleFound) Then
'TODO Create Contact and populate the New TSR form
Else
PageNavigation.MovetoPage(PageNavigation.PageID.Ne wVehicle)
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.Length = 0) Then
Return True
'Else
' strMessage = "You must complete the following fields before
continuing:" & vbCrLf & strMessage
' DisplayClientMessage("message", strMessage)
' Return False
'End If

End Function

Private Sub cmdGetVIN_Click(ByVal sender As System.Object, ByVal e
As System.Web.UI.ImageClickEventArgs) 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.fldVehicleID,
tblVehicles.fldCustomerID, tblVehicleModels.fldVehicleModel,
tblVehicleVariants.tblVehicleVariant, " _
& "tblVehicles.fldRegistrationNumber FROM tblVehicles INNER
JOIN tblVehicleModels ON " _
& "tblVehicles.fldVehicleModelID =
tblVehicleModels.fldVehicleModelID INNER JOIN tblVehicleVariants ON "
_
& "tblVehicles.fldVehicleVariantID =
tblVehicleVariants.fldVehicleVariantID " _
& "WHERE (tblVehicles.fldVIN = '" & Me.txtVIN.Text & "')"
objDR = SqlHelper.ExecuteReader(ConfigSettings.SystemConne ctionString,
CommandType.Text, 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
mblnVehicleFound = True
LogonUser.VehicleID = objDR("fldVehicleID")

Dim intCustomerID As Integer =
CType(objDR("fldCustomerID"), Integer)
Me.txtDetails.Text = objDR("fldVehicleModel") & ", " &
objDR("tblVehicleVariant") & ", " & objDR("fldRegistrationNumber")

' Close reader
objDR.Close()
strSQL = "SELECT tblCustomers.fldTitle,
tblCustomers.fldFirstName, tblCustomers.fldSurname,
tblCustomers.fldCustomerID, " _
& "tblCustomers.fldEmailAddress,
tblAddresses.fldDaytimeTel, tblAddresses.fldMobileTel,
tblAddresses.fldFax " _
& "FROM tblCustomers INNER JOIN tblAddresses ON
tblCustomers.fldCustomerID = tblAddresses.fldCustomerID " _
& "WHERE ((tblAddresses.fldPrimaryAddress = - 1) AND
(tblCustomers.fldCustomerID = " & intCustomerID & "))"
objDR = SqlHelper.ExecuteReader(ConfigSettings.SystemConne ctionString,
CommandType.Text, strSQL)
While objDR.Read
Me.txtEmail.Text = CType(objDR("fldEmailAddress"),
String)
Me.txtTitle.Text = CType(objDR("fldTitle"), String)
Me.txtFirstName.Text = CType(objDR("fldFirstName"),
String)
Me.txtSurname.Text = CType(objDR("fldSurname"), String)
Me.txtTelephone.Text = CType(objDR("fldDaytimeTel"),
String)
Me.txtMobile.Text = CType(objDR("fldMobileTel"),
String)
Me.txtFax.Text = CType(objDR("fldFax"), String)

End While
End While

' Close reader
objDR.Close()

If (Not (blnHasRows)) Then

mblnVehicleFound = 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(HttpContext.Current.Session("BadVIN"), String)
<> Me.txtVIN.Text)) Then
DisplayClientMessage("VIN", "This VIN is not known to
the system. Please check that it is correct and press the button
again")
Else
DisplayClientMessage("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.Current.Session("BadVIN") = Me.txtVIN.Text
End If

Catch ex As Exception
Finally
objDR.Close()
End Try
End Sub

Private Sub Page_Unload(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Unload

Try
Call QuickAddressClass.CloseQuickAddress()
Catch
End Try

End Sub

Private Sub lstAddresses_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
lstAddresses.SelectedIndexChanged
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.SelectedIndex

Try

' Does the selected Item have subitems?
If (QuickAddressClass.AddressSubItems(intValue,
colAddressed)) Then

' Yes it does, use the collection returned to populate the
your control
If (colAddressed.Count > 0) Then
lstAddresses.Items.Clear()
For intCount = 1 To colAddressed.Count
lstAddresses.Items.Add(colAddressed.Item(intCount) )
Next
End If
cmdBackUp.Enabled = True
cmdOk.Enabled = False
Else

' Get the item selected and populate the address text
boxes
QuickAddressClass.GetAddress(intValue, colAddressed)

' This always returns a collection of 5 strings, the last
one being the postcode.
'mcolSelectedAddress = colAddressed
cmdOk.Enabled = True
End If
Catch ex As Exception
'lblError.Text = ex.Message
End Try
End Sub
End Class
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
te********@hotmail.com (Edward) wrote in message news:<25**************************@posting.google. com>...
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 SelectedIndexChanged 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

[...]

like duh! It's not the SelectedIndex that holds the value of the
selected item, it's the SelectedItem.Value.

Sorted. Sorry if I wasted your time or bandwidth.

Edward
--
The reading group's reading group:
http://www.bookgroup.org.uk
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.