Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am fairly new to Web forms. I am using VB.net Web Forms, running under IIS, on a Windows10 desktop, to develop an ecommerce web site.

The form in question, the Catalog form, allows the user to select the make, model, year and engine, for the vehicle for which he is looking for parts. This form gets those 4 data items by the user clicking sequentially on each of the list boxes on the form.

I have a web form with 4 unbound aspxListBox Controls. They are Make, Model, Year, and Engine. Each one is filled by a SQLServer Stored Procedure. Each Listbox has one column.

The Makes Listbox stored procedure has no parameters. It fills properly on the form Load event. The models listbox stored procedure has 1 parameter based on the "make" he clicks. The years listbox stored procedure has 2 parameter based on the "make" and "model" he has clicked. The engine listbox stored procedure has 3 parameter based on the "make", "model" and "year" he has clicked.

The User fills each Listbox progressively. He selects a "Make", by clicking on an list item in that listbox .

I get the value (text, whatever) of the list item the user clicked on.
Then I set a "Session variable" to that value e.g. Session("Acura") and use that Session as a pramater to execute the stored procedure to fill the "Models" listbox . At this time after postback or whatever, the Makes Listbox still displayy all rows, and the Models Listbox displays the Models of the "Make" selected. e.g. Make = "Acura", Models Listbox displays "TL", "TSX"… one in each row of the Models listbox .

The User then selects a "Model", by clicking on a list item in that listbox .
Then I set a "Session variable" e.g. Session("TSX") and use the Session("Acura") and Session("TSX") values as pramaters to execute the stored procedure for the "Years" listbox . At this time after postback or whatever is required, the Makes and Models listboxes still display all rows, and the Year Listbox displays all Years for that make and model.

The User then selects a "Year", by clicking on a list item in that listbox .
Then I set a "Session variable" e.g. Session("2009") and use the Session("Acura") and Session("TSX") and Session("2009") values as pramaters to execute the stored procedure for the "Engine" listbox. At this time after postback or whatever is required, the Make, Model, and Year listboxes still display all rows, and the Engine Listbox displays all engines for that make, model, and year.

Finally the user selects an engine, by clicking on a list item in that listbox .

Then I set a "Session variable" e.g. Session("2.4 L4 Gas"). At this point, the user is redirected to another Web form (Select Parts) where the session variables are used by a stored procedure to fill a Listbox displaying all of the available products for that vehicle's make, model, year. and engine.

My problem is that the first time through, it all works perfectly. As the user selects each item from a list, the "SelectedIndexChanged" event fires properly, and the session variable is set.

Protected Sub listboxMakes_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ListBoxMakes.SelectedIndexChanged
        Session("SelectedMake") = ListBoxMakes.SelectedItem.Text
        Session("Lookup2Show") = "Models"

    End Sub


As the form load event is fired again, the next list box is filled based on the Session variable(s) passed to it.

the ASPX code that handles this is:
<asp:ListBox ID="ListBoxMakes" runat="server" AutoPostBack="True" OnSelectedIndexChanged="FillModels" CssClass="auto-style3" Rows="40" ></asp:ListBox>
<asp:ListBox ID="ListBoxModels" runat="server" AutoPostBack="True" OnSelectedIndexChanged="FillYears" CssClass="auto-style1" Rows="40"></asp:ListBox>
<asp:ListBox ID="ListBoxYears" runat="server" AutoPostBack="True" OnSelectedIndexChanged="FillEngines" CssClass="auto-style2" Rows="40"></asp:ListBox>
<asp:ListBox ID="ListBoxEngines" runat="server" AutoPostBack="True" CssClass="auto-style5"></asp:ListBox>


My problem is twofold.

First, should the user click on the wrong Model of car, and the Years listbox is already filled with the years that make and model was manufactured, then if he realizes what has happened and tries to click on another model in the Models listbox to fix the problem, then the "SelectedIndexChanged" event does not fire.

The second problem is if he makes the same mistake but fails to notice until the Parts select screen is displayed. There are four buttons btnMake, btnModel, btnYear and btnEngine he can click on to return to the Catalog form. based on the button he selects, the Session Variables are cleared appropriately.

E.G.
Protected Sub ASPXModelButton_Click(sender As Object, e As EventArgs) Handles ASPXModelButton.Click
    Session("Lookup2Show") = "Models"
    Session("WebOrderNumber") = 0
    Session("Model") = Nothing
    Session("SelectedModel") = Nothing
    Response.Redirect("Catalog.aspx")
End Sub


In this case, the Makes list box is filled, the Models Listbox is cleared and filled based on the Session("MakeSelected") variable. the process of doing this also clears out the other two listboxes, so that when the user selects a different Model the Years list box will be filled correctly.

The problem, again, is the "SelectedIndexChanged" event does not fire. when the user clicks in the Models listbox.

I will be happy to provide the complete ASPX and ASPX.VB code if you think you can help and need to see it.

Thanking you in advance, Slow Eddie.

What I have tried:

Microsoft help files, and walkthroughs. I don't go to Stack Overflow anymore.
Posted
Comments
j snooze 5-Aug-21 17:43pm    
Do you have an IsPostback logic or anything in your pageload erroring or preventing the code from getting to the SelectIndexChanged events? Might try debugging there to see if anything is erroring out before it gets to the SelectIndexChanged because the PageLoad event always runs on postback before the subsequent events are fired.

I would at least start there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900