简体   繁体   English

来自ModalPopup的PostingBack,但保持可见?

[英]PostingBack from ModalPopup, but keeping it visible?

I have a ModalPopup that will contain a gridview and 4 fields to enter items into the gridview itself. 我有一个ModalPopup,它将包含一个gridview和4个字段,用于将项目输入gridview本身。

Is it possible to postback to the server and update the gridview while keeping the modal open? 是否可以在保持模态打开的同时回发到服务器并更新gridview?

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. 有人提到使用jQuery的解决方案,但这很久以前。

Wrapping the popup's content (ie not the popup itself!) in an UpdatePanel worked for me. 在UpdatePanel中包装弹出窗口的内容(即不是弹出窗口本身!)对我有用。

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. UpdatePanel给了我我需要的确切行为,没有额外的代码。

Thanks to Patel Shailesh for the idea. 感谢Patel Shailesh的想法。

<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" />

The key to doing this is going to be using AJAX of some flavor -- Microsoft.Ajax or jQuery Ajax. 这样做的关键是使用某种风格的AJAX - Microsoft.Ajax或jQuery Ajax。 If the UpdatePanel is not working, then I'd suggest using jQuery to submit back to the server using AJAX. 如果UpdatePanel不起作用,那么我建议使用jQuery使用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. 这将涉及创建WebMethod以接受服务器端的AJAX帖子,并使用jQuery检测客户端以发送请求/接收响应。 Without seeing your HTML it's a little hard to be very specific. 如果没有看到你的HTML,那就很难具体了。

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
    });
 });

I am not sure if this would work, but try to put whatever inside the modalpopup in a UpdatePanel 我不确定这是否可行,但尝试将modalpopup中的任何内容放在UpdatePanel中

Please if this works don't hate me after you release, I hate updatepanels too 如果这个作品在发布后不讨厌我,我也讨厌updatepanels

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; 一种丑陋的选择是在首先显示模态弹出窗口并设置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. 然后在关闭弹出窗口时检查页面加载并最终再次回发并将其设置为false /从viewstate中删除它。

(these kind of issues are why I hate the ajax toolkit) (这些问题是我讨厌ajax工具包的原因)

I was experimenting with the modalpopupextender, and find a ugly solution. 我正在尝试使用modalpopupextender,并找到一个丑陋的解决方案。 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: 如果代码隐藏中的OkBtn_Click有一个调用:

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

Then the modalpopupextender is not closed. 然后modalpopupextender没有关闭。 This happened too to this guy: http://forums.asp.net/t/1591860.aspx 对于这个家伙来说也是如此: http//forums.asp.net/t/1591860.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM