2012-05-24 2 views
0

동적 테이블이 page_load에서 빌드됩니다.동적 이미지 버튼 이벤트 핸들러가 실행되지 않습니다.

전체 페이지 다시 게시없이 동적으로 행을 추가 할 수 있도록 테이블을 업데이트 패널에 넣었습니다. 각 행에는 텍스트 상자를 포함하는 처음 4 개의 셀과 행을 삭제해야하는 이미지 버튼 인 4 번째 셀이 있습니다.

그러나 행을 제거하는 이미지 버튼은 다시 게시되지만 이벤트 처리기 하위는 실행되지 않습니다.

테이블을 포스트 백에서 다시로드하기위한 세션 변수로 설정했습니다. 손익 페이지가 포스트 백에있는 경우 page.init에

<%--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> 

는이

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 

답변

0

동적 컨트롤이 있어야합니다. 마다 시간마다 ASP.NET에서 동적으로 생성 된 컨트롤에 뷰 상태, 포스트 백 데이터 및 이벤트 와이어를 복원 할 수 있도록 페이지가 만들어집니다. 따라서 다시 게시 할 때 다시 작성하는 것을 잊지 마십시오.

모든 게시물에 작성하는지 확인하십시오.

+0

초기 테이블은 page_load에서 생성되고 세션 변수로 설정된 다음 범위에 추가됩니다. page_init에 다시 게시하는 동안 나는 span 컨트롤을 세션으로 재설정합니다. span_tblHA.Controls.Add (CType (Session ("tblHA"), Table)). 그것들은 "재창조 된"요구 사항을 충족시키지 못합니까? – Dan

관련 문제