在asp.net中的图像控件中生成onclick事件

时间:2012-02-06 16:47:25

标签: asp.net html vb.net

我在asp.net中有一位数据列表

我正在使用vb和asp

现在我的代码如下

<table border="0" cellpadding="0" cellspacing="0" >

<tr>

    <br />

   <td>

   Question Number:

        <asp:Label ID="Label3" runat="server" Text='<%# Eval("Question_no") %>' />

        <br />

   Cust_id:

        <asp:Label ID="Cust_idLabel" runat="server" Text='<%# Eval("Cust_id") %>' />

        <br />

        Question:

        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Question") %>' />

        <br />

        Time:

        <asp:Label ID="Label2" runat="server" Text='<%# Eval("Date_time") %>' />

        <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/ImagesFolde/Chrysanthemum.jpg" Height="50" Width="50" **OnClientClick="s()"**/>

所有这些都在datalist中,你可以看到

所以会重复...

我在其中放了一张图片

现在我想在点击任何图像时调用方法

我在vb中创建了一个名为 s()的子

我想称之为

我在 clientclick()事件上使用但不起作用

该怎么办?

3 个答案:

答案 0 :(得分:1)

<asp:ImageButton  ID="imgexpand" runat="server" ImageAlign="Bottom" ImageUrl="~/img/plus.png" OnClick="s" />

您不需要控件onclick语句中的() 这将触发vb代码中的sub s()过程

答案 1 :(得分:0)

你使用onclientclick - 你用javascript / jquery创建了你的函数吗? (服务器端不会被解雇)

例如: 如果你这样称呼客户端方法:

OnClientClick="return myFunction();"

那么你的函数应该在标题中如下:

<script type=text/javascript>
   function myFunction()
   {
       alert("activated here");
   }
</script>

答案 2 :(得分:0)

假设您有一个数据列表:

ASPX:

<asp:DataList id="ItemsList" OnItemCommand="Item_Command" runat="server">
   <ItemTemplate>
      <asp:LinkButton id="SelectButton" Text="Select" CommandName="ModifyRow" 
      runat="server" CommandArgument='<%#Eval("Id")%>' />
   </ItemTemplate>
  </asp:DataList>

VB(代码背后): 在这里,我从'<%#Eval("Id")%>'获取id并将一些产品绑定在项目符号列表中:

Protected Sub ItemsList_ItemCommand _
    (source As Object, e As RepeaterCommandEventArgs) _
    Handles Categories.ItemCommand
    If e.CommandName = "ModifyRow" Then
        ' Determine the CategoryID
        Dim categoryID As Integer = Convert.ToInt32(e.CommandArgument)
        ' Get the associated products from the ProudctsBLL and
        ' bind them to the BulletedList
        Dim products As BulletedList = _
            CType(e.Item.FindControl("ProductsInCategory"), BulletedList)
        Dim productsAPI As New ProductsBLL()
        products.DataSource = productsAPI.GetProductsByCategoryID(categoryID)
        products.DataBind()
    End If
End Sub
相关问题