Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 动态生成的图像按钮无法运行asp.net web app_Vb.net_Web - Fatal编程技术网

Vb.net 动态生成的图像按钮无法运行asp.net web app

Vb.net 动态生成的图像按钮无法运行asp.net web app,vb.net,web,Vb.net,Web,我正在使用Visual basic中的asp.net Web应用程序。我想在按下动态生成的图像按钮时更改iframe源。当我点击普通按钮时,代码被执行,而当我想用图像按钮执行代码时,它不会执行。为什么?我在网上使用了很多代码,但都不起作用 HTML <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="index.aspx.vb" Inherits="Web

我正在使用Visual basic中的asp.net Web应用程序。我想在按下动态生成的图像按钮时更改iframe源。当我点击普通按钮时,代码被执行,而当我想用图像按钮执行代码时,它不会执行。为什么?我在网上使用了很多代码,但都不起作用

HTML
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="index.aspx.vb" Inherits="WebApp.index" %>


<!DOCTYPE html>


<html xmlns="https://www.w3.org/1999/xhtml">;
<head runat="server">
    <title>WebApp</title>
    <script language="VB" runat="server">
        Dim connection As New System.Data.SqlClient.SqlConnection("Data Source=myserver;Initial Catalog=mycatalog;Persist Security Info=True;User ID=Guest")
        Dim table1 As System.Data.DataTable
        Dim id As Int16
        Overloads Sub showproduct(ByVal sender As Object, ByVal e As ImageClickEventArgs)
            MatchesCounter.Text = "Test"
        End Sub


   </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>Name</td>
                    <td><asp:TextBox ID="nameButton" runat="server"></asp:TextBox></td>
                </tr>
            </table>
            <asp:Button ID="SearchButton" runat="server" Text="Search" />
        </div>
        <asp:Label ID="MatchesCounter" runat="server"></asp:Label>
        <br />
        <asp:Table ID="ProductList" runat="server">
            <asp:TableRow>
                <asp:TableCell></asp:TableCell>
                <asp:TableCell>Name</asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    </form>
    <iframe name="VideoFrame" id="VideoFrame" accesskey="VideoFrame" class="VideoFrame" runat="server"></iframe>
</body>
</html>

VB

Protected Sub Search_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
        search()
    End Sub
    Private Sub search()
        Dim command As New SqlCommand("select top 20 ID, [Name], MainPicture from File1 where [Name] like '%" + nameButton.Text + "%' and Type = 'M' and Visible='1'", connection)
        Dim adapter As New SqlDataAdapter(command)
        Dim table As New DataTable()
        adapter.Fill(table)
        table1 = table
        MatchesCounter.Text = "Found: " + table.Rows.Count.ToString
        Dim top As Short = 0
        For Each product In table.Rows
            Dim row As TableRow = New TableRow()
            Dim p As ImageButton = New ImageButton
            p.ID = top.ToString
            p.ImageUrl = table.Rows(top)(2)
            p.Height = 170
            AddHandler p.Click, AddressOf Me.showproduct
            Dim cell1 As TableCell = New TableCell()
            cell1.Controls.Add(p)
            Dim cell2 As TableCell = New TableCell()
            cell2.Text = product(1).ToString
            row.Cells.Add(cell1)
            row.Cells.Add(cell2)
            ProductList.Rows.Add(row)
            top += 1
        Next
    End Sub
    Protected Sub showproduct(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        ClientScript.RegisterStartupScript(Me.GetType, "ImageButton_Alert", "alert('ImageButton clicked!');", True)
    End Sub
HTML
;
网络应用
将连接作为新System.Data.SqlClient.SqlConnection(“数据源=myserver;初始目录=mycatalog;持久安全信息=True;用户ID=Guest”)
Dim表1作为System.Data.DataTable
Dim id为Int16
重载子showproduct(ByVal发件人作为对象,ByVal e作为图像ClickEventArgs)
matchesconter.Text=“测试”
端接头
名称

名称 VB 受保护的子搜索\u单击(发件人作为对象,e作为事件参数)处理搜索按钮。单击 搜索() 端接头 专用子搜索() Dim命令作为新的SqlCommand(“从文件1中选择前20个ID,[Name],main图片,其中[Name]类似于“%””+nameButton.Text+“%”,类型='M'和Visible='1',连接) Dim适配器作为新的SqlDataAdapter(命令) Dim表作为新数据表() 适配器填充(表) 表1=表 matchesconter.Text=“找到:”+table.Rows.Count.ToString 将顶部调暗为短=0 对于表.行中的每个产品 按TableRow调整行=新建TableRow() 将p变暗为ImageButton=新建ImageButton p、 ID=top.ToString p、 ImageUrl=表格行(顶部)(2) p、 高度=170 AddHandler p.Click,Me.showproduct的地址 Dim cell1作为TableCell=新TableCell() 单元格1.控件.添加(p) Dim cell2 As TableCell=新的TableCell() cell2.Text=产品(1).ToString 行.单元格.添加(单元格1) 行.单元格.添加(单元格2) ProductList.Rows.Add(行) 顶部+=1 下一个 端接头 受保护的子showproduct(ByVal发件人作为对象,ByVal e作为图像ClickEventArgs) RegisterStartupScript(Me.GetType,“ImageButton_警报”,“警报('ImageButton clicked!');”,True) 端接头