472,975 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

Listbox SelectedIndexChanged not firing (Autopostback = True)

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
1 8183
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: yop | last post by:
All When I try to get the text from my listbox I am get an error which is listed below. Any ideas? Thanks Object reference not set to an instance of an object.
2
by: CW | last post by:
Yes, Autopostback is true, and it doesn't make an iota of difference at all. HTML snippet and code (behind) snippet is as below: <asp:dropdownlist id="ddlLoginType" runat="server" Width="163px"...
1
by: Daniel | last post by:
hi, I had an asp:listbox, and everytime i click item inside, the bar automatically go to the top, is there any way to keep the scroll position? I turn on the smartNavigation, it still doesn't...
6
by: Steve | last post by:
Hi, I open up a webform (vb.net) and populate a listbox control on the Page load event. If I click on (select) and item from the listbox I want to write the value of the selected item to a...
6
by: msnews.microsoft.com | last post by:
Hi All, I am creating a control with ASP "ListBox" control. Also I have added necessary code to handle the ListBox.SelectedItemChanged Event. But surprisingly the control is not comng to...
2
by: rdb | last post by:
VB.NET web program with a webform w/2 dropdownlistboxes, set to AutoPostBack TRUE, selection in either dropdown fires the SelectedIndexChanged events correctly UNTIL I navigate to second webform in...
2
by: teo | last post by:
I have a Listbox, if I set EnableViewStarte = False the AutopostaBack fired by SelectedIndexChanged doesn't work. The 'SelectedIndexChanged' event should call
2
by: jnoody | last post by:
The problem I am having is with the SelectedIndexChanged event not always firing or the SelectedIndex property not being correct when the event does fire. The code is below, but here are some...
9
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback)....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.