0

I am trying to figure out how to set the ID variable in the itemCommand block, and then share it in the PagePropertiesChanged block.

I am wondering if this is possible to do?

Here is a simplified example of what I am trying to do,

Public Shared ID As Integer

 Private Sub DataListCategories_ItemCommand(source As Object, e As DataListCommandEventArgs) Handles DataListCategories.ItemCommand

    If (e.CommandName.Equals("ClickCategory")) Then

            ID = e.CommandArgument

    End if

 End sub

 Private Sub ListViewGallery_PagePropertiesChanged(sender As Object, e As EventArgs) Handles ListViewGallery.PagePropertiesChanged


    Me.ListViewGallery.DataSource = Dal.GetPhotographyByCategory(ID)
        Me.ListViewGallery.DataBind()

 End Sub
Abdellah OUMGHAR
  • 3,627
  • 1
  • 11
  • 16

2 Answers2

0

It appears you are trying to persist the ID in a Shared variable (static in C#) between post backs but you must understand the nature of shared/static variables in ASP.NET.

This is covered well in Lifetime of ASP.NET Static Variable

You can persist the ID using the Session object like:

Session("ID") = ID

Or use a something like a ASP.NET hidden field

<asp:hiddenfield id="IDField" runat="server" value="0"/>

Set it like this:

IDField.Value = ID
Community
  • 1
  • 1
imagehaven
  • 21
  • 3
0

I am sort of confused at what you are saying. I think you are saying put a hidden field in the html, and call it in code behind using a findcontrol?

can it not be done the other way?