I've inherited a VB.Net application that I'm testing and the ItemCommand event is not firing... It is a VB.Net 4.0 application.
I've searched the web for this error and doubhle checked the code in the application.
I know this event is supposed to fire on a postback after the page_load event. However, when I click on the ImageButton (to force a postback and hopefully execute the ItemCommand event), the Page.IsPostBack property is still set to FALSE, thereby never being able to execute the ItemCommand event. I don't know why this property would still be set to FALSE. Evidently, I need a way to signify to the page that a postback is occurring. The ImageButton should take care of this since it has the runat="server" tag.
Below are the code snippets. Can someone please inform me what I would need to do in order to fire the Item command? What I said above is true, I believe. I don't know why after the page loads and I press the ImageButton that the property would still be set to FALSE.
HTML
<asp:DataList ID="lstReferrals" runat="server" DataKeyField="ReferringAffiliateID"
OnItemCommand="lstReferrals_ItemCommand" CellPadding="4" Summary="Referral Design Table"
Width="800"><ItemTemplate>
<tr class="small" bgcolor="#FFFFFF">
<td>
<asp:ImageButton ID="btnSelect" AlternateText="Select" ImageUrl='<%# NodeImage(1) %>'
CommandName="select" runat="server" />CODE BEHINDPrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not (Request.Params("ItemIndex") Is Nothing) Then
itemIndex = Int32.Parse(Request.Params("ItemIndex"))
Else
itemIndex = Convert.ToInt32(Null.SetNull(itemIndex))
End If
If Not Page.IsPostBack Then
LoadReferrals()
If Not Null.IsNull(itemIndex) Then
lstReferrals.SelectedIndex = itemIndex
LoadReferrals()
End If
End If
End Sub
Protected Sub lstReferrals_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles lstReferrals.ItemCommand
Try
errormessage.Visible = False
' Determine the command of the button (either "select" or "collapse")
Dim command As String = CType(e.CommandSource, ImageButton).CommandName
' Update asp:datalist selection index depending upon the type of command
' and then rebind the asp:datalist with content
Select Case command
Case "collapse"
lstReferrals.SelectedIndex = -1
LoadReferrals()
Case "select"
lstReferrals.SelectedIndex = e.Item.ItemIndex
LoadReferrals()