Search code examples
ajaxmodalpopupextender

ModalPopupExtender with Gridview


I have a Gridview, inside my GridView I add Linkbuttons to a certain column. What I want to do is when you click on the LinkButton created in my GridView I want my ModalPopupExtender to show.

LinkButton created in RowDataBound:

Private Sub grdDetails_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdDetails.RowDataBound
Try
  Try
    If Not iColAttachent Is Nothing Then
      For Each i In iColAttachent
        If e.Row.DataItem(i - 1).ToString.Trim.Length > 0 Then
          Dim c As New TableCell
          Dim LB As New LinkButton
          Dim strBookNo As String = e.Row.DataItem(i - 1).ToString

          ' Create link
          LB.ID = "LB_" & strBookNo
          LB.Text = strBookNo.Substring(strBookNo.IndexOf("_") + 1)
          LB.ToolTip = "Click to change book number"
          LB.Attributes.Add("AutoPostBack", "False")
          LB.Attributes.Add("OnClick", "ShowModal()")
          'HL.Attributes.Add("runat", "server")

          e.Row.Cells().RemoveAt(i)
          e.Row.Cells().AddAt(i, c)
          c.Controls.Add(LB)
        End If
      Next
    End If
  Catch
    ' nothing to do
  End Try
Catch ex As Exception

End Try
End Sub

JavaScript for showing my ModalPopupExtender:

<script language="javascript" type="text/javascript">
    function ShowModal() {
        var modal = $find('ModalPopupExtender1');
        modal.show();
    }
</script>

ModalPopupExtender

<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="LinkButton1" PopupControlID="Panel1" DropShadow="true"
            BackgroundCssClass="modalBackground" CancelControlID="cmdCancel" BehaviorID="ModalPopupExtender1" Drag="true">

            </asp:ModalPopupExtender>

What the issue is when I click on the LinkButton my ModalPopupExtender does show but within in a second it disappear again. Not sure if it is because of PostBack or not.


Solution

  • Fixed the problem by adding a link button and assign it to the modalpopup. perhaps not the best way to do it but it works.