OnClick再次只激发一次 - VB.NET

时间:2012-11-27 19:18:45

标签: asp.net

我在.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"/>&nbsp;

 <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事件中的代码隐藏如下:

 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

0 个答案:

没有答案