我在 .aspx 页面的 Datalist 中有一个 asp:ImageButton。我在位于数据列表之外的页面上也有一个 img 控件。datalist 仅用于生成缩略图。单击一个时,相应的图像应出现在较大的 img 控件中。该事件触发一次,但如果我尝试点击另一个缩略图,它不会再次触发该事件。但是,如果我等待 60-90 秒,我可以单击另一个缩略图,事件将再次触发。我不知道什么会导致这样的事情,它已经让我发疯了 2 天。我想这一定很简单,但我一直在互联网上搜索答案,似乎找不到答案。如果有人可以提供帮助,将不胜感激!
.aspx页面中的按钮代码如下:
<img height="15" src="images/1x1.gif"><asp:image id="ProductImage" runat="server" height="209" width="309"/>
<asp:DataList id="MoreColors" runat="server" RepeatColumns="1" >
<ItemTemplate>
<table style: border="0" width="75">
<tr>
<td style: width="75" valign="middle" align="right">
<asp:ImageButton ID="imgBtn" runat="server" ImageUrl='<%# "ProductImages/Thumbs/" + Eval("DetailImage")%>' height="50" Width="50" OnCommand="imgBtn_Click" CommandArgument='<%# Container.ItemIndex %>'/> </a>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
Onclick 事件中的 Code-behind 如下:
Protected Sub imgBtn_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
Dim ib As ImageButton = DirectCast(sender, ImageButton)
ProductImage.ImageUrl = ib.ImageUrl
MoreColors.SelectedIndex = Convert.ToInt32(ib.CommandArgument)
ProductImage.Focus()
End Sub
Page_Load 代码如下:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ProductID As Integer = CInt(Request.Params("ProductID"))
If Not Page.IsPostBack Then
Dim ImageCatalogue As ASPNET.LOVEDAT.ProductsDB = New ASPNET.LOVEDAT.ProductsDB()
MoreColors.DataSource = ImageCatalogue.GetThumbnails(ProductID)
MoreColors.DataBind()
Dim Colorlist As ASPNET.LOVEDAT.ProductsDB = New ASPNET.LOVEDAT.ProductsDB
AvailableColors.DataSource = Colorlist.GetAvailableColors(ProductID)
AvailableColors.DataValueField = "ColorID"
AvailableColors.DataTextField = "ColorName"
AvailableColors.DataBind()
' Obtain Product Details
Dim products As ASPNET.LOVEDAT.ProductsDB = New ASPNET.LOVEDAT.ProductsDB()
Dim myProductDetails As ASPNET.LOVEDAT.ProductDetailsList = products.GetProductDetail(ProductID)
' Update Controls with Product Details
desc.Text = myProductDetails.Description
UnitCost.Text = String.Format("{0:c}", myProductDetails.UnitCost)
ProductName.Text = myProductDetails.ProductName
SKU.Text = myProductDetails.SKU.ToString()
ProductImage.ImageUrl = "ProductImages/" & myProductDetails.ProductImage
addToCart.NavigateUrl = "AddToCart.aspx?ProductID=" & ProductID
ReviewList.ProductID = ProductID
AlsoBoughtList.ProductID = ProductID
End If
End Sub