Priyansh
Priyansh

Reputation: 147

Modalpopupextender inside gridview in asp.net

I have a gridview in which some columns and view details link button is there.I want to open a popup window containing another gridview containing some details.To do this I am passing store number as a command argument from view details link button.But problem is that popup is being opened but server side event LinkViewDetail_Command is not getting called as a result gridview is showing nothing. Suggest me some modification in this code or another way of doing this?

<asp:TemplateField HeaderText="View Detail" >
            <ItemTemplate>
             <asp:LinkButton ID="LinkButtonViewDetail" Text="View" runat="server"  CommandArgument='<%#Eval("StoreNumber").ToString()%>' OnCommand="LinkViewDetail_Command"/>
             <ajax:ModalPopupExtender runat ="server" ID="ModalPopupWarning" 
            TargetControlID="LinkButtonViewDetail"
            PopupControlID="PanelPopUp"  
            CancelControlID="ButtonCancel"
                            ></ajax:ModalPopupExtender>
            </ItemTemplate>
          </asp:TemplateField>



 Public Sub LinkViewDetail_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
    Try

        GridViewViewNewStoreTransitionStore.DataSource = m_DataAccess.GetFinalStoreCloseAcquisition(CInt(e.CommandArgument))
        GridViewViewNewStoreTransitionStore.DataBind()

    Catch ex As Exception
        Common.WriteLog(ex)
        Response.Redirect("..\Errors.aspx", False)
    End Try
End Sub

Upvotes: 1

Views: 6082

Answers (1)

anouar.bagari
anouar.bagari

Reputation: 2104

Put your ModalPopupExtender outside the grid view and initialize it like this

 <ajax:ModalPopupExtender runat ="server" ID="ModalPopupWarning" 
        TargetControlID="PanelPopUp" <!--dont use the LinkButtonViewDetail as a TargetControlID use the    id of any other control -->
        BehaviorID="PanelPopUpBI" 
        PopupControlID="PanelPopUp"  
        CancelControlID="ButtonCancel">
 </ajax:ModalPopupExtender>

then use the OnRowCreated event from your gridview to register detail view link as an asynchronous trigger

protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       foreach (Control cells in e.Row.Controls)
       {
         foreach (Control link in cells.Controls)
         {
            if (link.GetType() == typeof(LinkButton))
            {
               // here i suppose that you have a master page
               (this.Master.FindControl("ToolkitScriptManager") as ScriptManager).RegisterAsyncPostBackControl(link);
            }
          }
       }
    }

}

in your aspx file use this script to show the pop up when the ajax request finished

 <script type="text/javascript">
  function pageLoad() { 
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);

        function endRequestHandler() {
            $find('PanelPopUpBI').show();
        }
    }
</script>

Upvotes: 1

Related Questions