Link to home
Create AccountLog in
Avatar of mpdillon
mpdillon

asked on

How to load different data after a Postback

I have a web page that displays product categories. When the user clicks on a Product Category, I want the same web page to display Product Information rather than Category information.

Here is what I see:
Initial page load

Private Sub SidePanel1_Init(sender As Object, e As EventArgs) Handles Me.Init
        LoadCategories()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        PublicFunctions.LoadPV()

        If Not IsPostBack Then
            LoadCategoryListBox()
            'LoadAllCategories()
        End If
End Sub

Open in new window


"LoadCategories" loads images that are buttons in the code behind file on the initial page load. This works fine.

Next a user would click on an Category image button. This would return the Category ID and from that ID I can return all the Product images for that Category. I want those images to appear on this page. The end result would be this page displaying only Product images and not any category images.

Here is what I see when a user clicks on a Category Image. The code for the "Init" event fires, then the "Page_Load" and finally the "ImageButton_Click" event fires. I have the code to load the product images located in the "ImageButton_Click" event. I have that code in that event because the button click event returns the ID number for the category which was clicked.

Here is the current sequence:
Private Sub SidePanel1_Init(sender As Object, e As EventArgs) Handles Me.Init
        ' LoadProductImages()
        LoadCategories()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        PublicFunctions.LoadPV()

        If Not IsPostBack Then
            LoadCategoryListBox()
            'LoadAllCategories()
        End If
End sub
Protected Sub ImageButton_click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        Dim s As String = String.Empty
        Dim ib As ImageButton = DirectCast(sender, ImageButton)
        s = ib.ID
        s = Mid(s, 8, Len(s))
        If IsNumeric(s) Then
            PublicVariables.CategeryIDNoIntegerP = Val(s)
            If PublicVariables.CategeryIDNoIntegerP = 0 Then
                LoadCategories()
            Else
                LoadProductImages()
            End If
        Else
            PublicVariables.CategeryIDNoIntegerP = 0
            LoadCategories()
        End If
        '

    End Sub

Open in new window


How can I arrange the code so that when a user clicks on a Category Image, the page refreshes with the Products for that category?
Thanks,
pat
Avatar of John Gates, CISSP, CDPSE
John Gates, CISSP, CDPSE
Flag of United States of America image

You can use an ASP panel control and show the panel after a choice is made.  The controls in the panel can be based on a selection in the initial controls that load:

https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel(v=vs.110).aspx

Hope this helps!
-J-
Avatar of mpdillon
mpdillon

ASKER

John,
I am not sure that would work. I cannot load the panel until the Button click event is fired. It is in the button click event that the ID number is returned. That ID number is needed to populate the panel. The button click event occurs after the INIT event.
ASKER CERTIFIED SOLUTION
Avatar of mpdillon
mpdillon

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account