2

I have a gridview that appears in a modal popup that is generated dynamically and is bound to a dynamically generated SqlDataSource.

I did this to hopefully take advantage of the gridview's automatic editing capabilities.

My problem is that when the edit button is clicked the modalpopup closes due to a full postback in spite of the fact that my gridview is in an update panel...

I looked at solutions here and here but neither fixed the problem. I've also tried every combination under the sun regarding the positioning of the ModalPopupExtender in relation to the update panel etc, and have tried changing UpdateMode to conditional as well.

Markup:

<span class="none"><asp:Button ID="btnDummy" runat="server" Text="Dummy" /></span>
<ajax:ModalPopupExtender ID="mpLabel" runat="server" TargetControlID="btnDummy" BackgroundCssClass="modalBackground" PopupControlID="pnlLabels"></ajax:ModalPopupExtender>
<asp:Panel ID="pnlLabels" DefaultButton="btnOk" Style="display:none;" runat="server">    
<div style="background-color:#fff;border:1px solid black;padding:7px;">                
<asp:UpdatePanel ID="upLabels" runat="server" ChildrenAsTriggers="true" EnableViewState="true" UpdateMode="Always">
    <ContentTemplate>
                <asp:Panel ID="pnlGv" runat="server" style="max-height:420px;width:700px;border-bottom:1px #ccc solid;" ScrollBars="Vertical">
                    <asp:PlaceHolder ID="phLabelInfo" runat="server"></asp:PlaceHolder>                    
                    <asp:PlaceHolder ID="phSDS" runat="server"></asp:PlaceHolder>    
                </asp:Panel>                                
    </ContentTemplate>        
</asp:UpdatePanel>
<asp:Button ID="btnOk" runat="server" Text="Ok" />
</div>
</asp:Panel>

Code Behind:

    Dim sdsLabels As New SqlDataSource
    sdsLabels.ID = "sdsLabels"
    sdsLabels.ConnectionString = System.Configuration.ConfigurationManager.AppSettings.Get("Generic Connection String")
    sdsLabels.ProviderName = "System.Data.SqlClient"
    sdsLabels.DeleteCommand = "DELETE FROM [JS_LABELS] WHERE [LABELID] = @LabelId"
    sdsLabels.SelectCommand = "SELECT [LABELID], [CIRCUITNUMBER], [PANELNUMBER], [ADDITIONAL1], [ADDITIONAL2], [ADDITIONAL3] FROM [JS_LABELS] WHERE [QUOTEITEMID] = @QuoteItemId"
    sdsLabels.UpdateCommand = "UPDATE [JS_LABELS] SET [CIRCUITNUMBER] = @CircuitNumber, [PANELNUMBER] = @PanelNumber, [ADDITIONAL1] = @Additional1, [ADDITIONAL2] = @Additional2, [ADDITIONAL3] = @Additional3 WHERE [LABELID] = @LABELID"
    sdsLabels.SelectParameters.Add(New Parameter("QuoteItemId", Data.DbType.Int32, e.CommandArgument.ToString()))
    sdsLabels.DeleteParameters.Add(New Parameter("LabelId", Data.DbType.Int32))

    Dim paramCollection As New ParameterCollection
    paramCollection.Add("CircuitNumber", Data.DbType.String, "")
    paramCollection.Add("PanelNumber", Data.DbType.String, "")
    paramCollection.Add("Additional1", Data.DbType.String, "")
    paramCollection.Add("Additional2", Data.DbType.String, "")
    paramCollection.Add("Additional3", Data.DbType.String, "")
    paramCollection.Add("LabelId", Data.DbType.Int32, "0")


    Dim ph As New PlaceHolder
    ph = CType(PageHelper.RecursiveFindControl(Page, "phSDS"), PlaceHolder)
    ph.Controls.Add(sdsLabels)

    Dim gv As New GridView
    ph = CType(PageHelper.RecursiveFindControl(Page, "phLabelInfo"), PlaceHolder)
    ph.Controls.Add(gv)

    gv.CssClass = "LabelsTable"
    Dim LabelId() As String = {"LabelId"}
    gv.DataKeyNames = LabelId
    gv.EnableViewState = True
    gv.AutoGenerateEditButton = True
    AddHandler gv.RowCommand, AddressOf gv_rowCommand
    gv.DataSourceID = sdsLabels.ID
    gv.DataBind()

    mpLabel.Show()
Community
  • 1
  • 1
personaelit
  • 1,633
  • 3
  • 31
  • 59

1 Answers1

0

In my experiences, the ModalPopupExtender will always close on a postback unless you explicitly ask it not to in the event triggered by the postback:

    btnSubmitRequest_ModalPopupExtender.Show();
Marcie
  • 1,169
  • 1
  • 10
  • 17
  • I am not sure what you mean. I tried hooking into the gridview rowcommand and called mpLabels.Show there but it never fired as the postback fired I think because the postback fired first and the datasource was re-binded when that happened. Also, since the gridview is in an update panel, only a partial postback should occur which *should* prevent the modal popup from disappearing. – personaelit Dec 01 '10 at 18:49