Question

I have a ModalPopup that will contain a gridview and 4 fields to enter items into the gridview itself.

Is it possible to postback to the server and update the gridview while keeping the modal open?

When you submit the fields and the postback occurs the modal closes has anyone done this before? Someone mentioned a solution using jQuery, but this was long ago.

Was it helpful?

Solution

The key to doing this is going to be using AJAX of some flavor -- Microsoft.Ajax or jQuery Ajax. If the UpdatePanel is not working, then I'd suggest using jQuery to submit back to the server using AJAX. This would involve creating a WebMethod to accept the AJAX post on the server side and instrumenting the client-side with jQuery to send the request/receive the response. Without seeing your HTML it's a little hard to be very specific.

Basic idea:

 $(function() {
    $('#modalSubmitButton').click( function() {
       $.ajax({
           url: 'path-to-your-web-method',
           dataType: 'json',  // or html, xml, ...
           data: function() {
               var values = {};
               values['field1'] = $('#field1ID').val();
               ...
               values['field4'] = $('#field4ID').val();
               return values;
           },
           success: function(data,status) {
              ... update page based on returned information...
           }
           ... error handling, etc. ...
       });
       return false; // stop any default action from the button clicked
    });
 });

OTHER TIPS

Wrapping the popup's content (i.e. not the popup itself!) in an UpdatePanel worked for me.

My popup content is a search panel with sortable/pageable grid of results. The UpdatePanel gave me the exact behaviour I require with no additional code.

Thanks to Patel Shailesh for the idea.

<asp:Panel runat="server" ID="PopupPanel" Height="650" Width="900" Style="display: none">
    <asp:UpdatePanel runat="server" ID="UpdatePanel1">
        <ContentTemplate>
            <!-- popup content -->
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>

<ajax:ModalPopupExtender runat="server" ID="PopupExtender" PopupControlID="PopupPanel"  
    TargetControlID="PopupButton" />
<asp:Button runat="server" ID="PopupButton" Text="Popup" />

I am not sure if this would work, but try to put whatever inside the modalpopup in a UpdatePanel

Please if this works don't hate me after you release, I hate updatepanels too

A kind of ugly option is to force a postback when showing the modal popup in the first place and setting a ViewState["ModelPopupOn"] = true; and then check that on page load and finally postback again and set it to false/remove it from viewstate when closing the popup.

(these kind of issues are why I hate the ajax toolkit)

I was experimenting with the modalpopupextender, and find a ugly solution. If the modal panel has a button that makes the postback to happen

<asp:Panel runat="server" ID="PopupPanel" Height="650" Width="900" Style="display: none">
    <asp:Button ID="OkButton" runat="server" Text="OK" OnClick="OkBtn_Click"  />
</asp:Panel>

If the OkBtn_Click in the code-behind has a call to:

System.Web.HttpContext.Current.Response.Write("<script></script>");

Then the modalpopupextender is not closed. This happened too to this guy: http://forums.asp.net/t/1591860.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top