最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Force a postback in Javascript for UpdatePanel? - Stack Overflow

programmeradmin0浏览0评论

I have a function to close a modal:

function closeModal(name) {
    $(name).modal('hide');
}

But, my page also has an update panel and I need to trigger it.

I tried __doPostBack('UpdatePanel1', '') with no luck.

Thanks

The problem is this:

$(document).ready(function () {
    createAutoClosingAlert('.success_alert', 6000);
    if(<%# IsAPostBack() %>){
        if(window.parent != null){
            window.parent.closeEditModal();
            window.parent.closeCalendarModal();
            window.parent.closeModal('#projectModal');
            window.parent.closeModal('#scheduleModal');
        }
    }
});

I call it from the parent so I cannot get the hidden ID.

I have a function to close a modal:

function closeModal(name) {
    $(name).modal('hide');
}

But, my page also has an update panel and I need to trigger it.

I tried __doPostBack('UpdatePanel1', '') with no luck.

Thanks

The problem is this:

$(document).ready(function () {
    createAutoClosingAlert('.success_alert', 6000);
    if(<%# IsAPostBack() %>){
        if(window.parent != null){
            window.parent.closeEditModal();
            window.parent.closeCalendarModal();
            window.parent.closeModal('#projectModal');
            window.parent.closeModal('#scheduleModal');
        }
    }
});

I call it from the parent so I cannot get the hidden ID.

Share Improve this question edited Apr 26, 2013 at 14:32 Lukasz Koziara 4,3205 gold badges34 silver badges44 bronze badges asked Apr 10, 2013 at 14:34 jmasterxjmasterx 54.2k99 gold badges327 silver badges574 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

One option is to put a hidden button inside your update panel

<div style="display:none">
  <asp:Button ID="Button2" runat="server" Text="Button" />
</div>

Then call the following in your script

document.getElementById('<%=Button2.ClientID%>').click();

The button click will cause a postback.

You can also look at Page.GetPostBackEventReference

发布评论

评论列表(0)

  1. 暂无评论