English 中文(简体)
动态图像按键事件处理程序未启动
原标题:Dynamic Image Button Event handlers not firing
  • 时间:2012-05-24 16:07:48
  •  标签:
  • asp.net
  • ajax

我有一个充满活力的桌子 建在页面上

我将表格放入更新面板中, 这样我就可以动态地添加行, 但没有完整页的后退。 每行头有4个包含文本框的单元格, 第4个单元格是需要删除行的图像按钮 。

然而,要删除行的图像按钮正在挂回, 但没有打开事件处理器 Sub 。 @ info: whatsthis

我将表格设置为会话变量, 用于在后加载时重新加载 。

<%--Update Panel with Image Button to add row--%>
<asp:UpdatePanel ID="pnlHA" runat="server" UpdateMode="conditional" >
 <ContentTemplate>
    <asp:ImageButton ID="imgAddHA" AlternateText="Add Row" ImageUrl="../images/plus_orange.png" style="width:17px; height:17px; cursor: hand;" runat="server" />
    <div style="height:100px; overflow:scroll; overflow-x:hidden;">
        <span runat="server" id="spanTBL_HA" />
    </div>   
 </ContentTemplate>
</asp:UpdatePanel>

如果 pnl 页面是后回页面, 则它会重新创建 space

    If pnlHA.Page.IsPostBack Then
        spanTBL_HA.Controls.Clear()
        spanTBL_HA.Controls.Add(CType(Session("tblHA"), Table))
    End If

正在添加到表格单元格的图像按钮

img = New ImageButton

Session("tblHA_Counter") = CInt(Session("tblHA_Counter")) + 1

img.AlternateText = "Delete Row"
img.Attributes.Add("style", "height: 10px; width: 10px; cursor: hand;")
img.ImageUrl = "../images/minus_red.png"
img.ID = "img_" & CInt(Session("tblHA_Counter")).ToString
AddHandler img.Click, AddressOf imgRemove_Click
img.Attributes.Add("runat", "server")

tc.Attributes.Add("style", "width:35px")
tc.Controls.Add(img)

点击活动

Protected Sub imgRemove_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
    Dim img As ImageButton = CType(sender, ImageButton)
    Dim delRow As TableRow = Nothing
    Dim rowIndex As Integer = 0

    For Each row As TableRow In CType(Session("tblHA"), Table).Rows
        If CType(row.Cells(3).Controls(0), ImageButton).UniqueID = img.UniqueID Then
            delRow = row
        End If
    Next

    If delRow IsNot Nothing Then
        CType(Session("tblHA"), Table).Rows.Remove(delRow)
    End If

    spanTBL_HA.Controls.Clear()
    spanTBL_HA.Controls.Add(CType(Session("tblHA"), Table))

End Sub
问题回答

需要重新创建动态控件 < em> every 该页面创建的时间, 以使 ASP. NET 能够恢复查看状态、 回溯数据和事件连接到动态创建控件上。 所以请记住在回溯上重新创建它们 。

请检查您是否要在每个邮局后退上创建它们 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签