Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...