__PostBack和updatePanel执行整页更新

时间:2021-08-22 16:09:41

I have a LiteralText which changes data when i click my control. I read up some guides and if I update the LiteralText within the UpdatePanel, it should only do a partial update but it updates the entire page.

我有一个LiteralText,当我点击我的控件时它会改变数据。我读了一些指南,如果我在UpdatePanel中更新LiteralText,它应该只进行部分更新,但它会更新整个页面。

I also read up another guide which says changing my __doPostBack to the clientID but didn't work too.

我还读了另一个指南,说明将__doPostBack更改为clientID但是也没有用。

So here is my aspx side code:

所以这是我的aspx侧码:

<div id="modalbox" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
    aria-hidden="true">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server"  ChildrenAsTriggers="true" UpdateMode="Conditional">
        <ContentTemplate>
           //Some Codes
                    <asp:Literal ID="modalTitle" runat="server"></asp:Literal>
           //More Codes
        </ContentTemplate>
    </asp:UpdatePanel>

My doPostBack code:

我的doPostBack代码:

        <script type="text/javascript">
            function changeModalTitle(eventTarget, parameter) {
                __doPostBack('<%=modalboxStaff.ClientID%>;', parameter)
            }
        </script>

And the code that calls both codes:

以及调用这两个代码的代码:

    <a href='#modalbox' data-toggle='modal' runat="server" id="modalboxStaff" **onclick="javascript:changeModalTitle('AddStaff', 'Sup World')**">

1 个解决方案

#1


1  

It's only going to trigger a partial postback if the control triggering the postback is in the update panel or the control is referenced in the triggers collection of the update panel.

如果触发回发的控件位于更新面板中,或者控件在更新面板的触发器集合中引用,则它将仅触发部分回发。

Could that be the issue?

这可能是问题吗?

to use __doPostBack to trigger the partial postback - you would need to reference the updatepanel ID in the __doPostBack call e.g.

使用__doPostBack来触发部分回发 - 您需要在__doPostBack调用中引用updatepanel ID,例如

__doPostBack('btnInsideUpdatePanel', '');

It's worth noting that the first argument is the ID not theClientID. If the clientID is used then you don't get the correct event handling on postback. Check out the answer on this forum

值得注意的是,第一个参数是ID而不是ClientID。如果使用clientID,则在回发时无法获得正确的事件处理。在这个论坛上查看答案

This article gives details

本文提供了详细信息

http://encosia.com/easily-refresh-an-updatepanel-using-javascript/

http://encosia.com/easily-refresh-an-updatepanel-using-javascript/

Any help?

有帮助吗?

EDIT

编辑

I would consider changing your anchor into a Link button. The anchor html control won't raise page events in the same way as a link button (although i believe what you have done can trigger a partial postback to be fair).

我会考虑将你的锚更改为Link按钮。锚点html控件不会像链接按钮一样引发页面事件(虽然我相信你所做的事情可以触发部分回发是公平的)。

and the below link is pretty much doing what you are which might be helpful if you haven't seen it

如果您还没有看到它,那么下面的链接几乎正在做您可能会有所帮助的内容

http://weblogs.asp.net/jeffreyzhao/archive/2008/04/26/refresh-the-updatepanel-using-javascript-code.aspx

http://weblogs.asp.net/jeffreyzhao/archive/2008/04/26/refresh-the-updatepanel-using-javascript-code.aspx

Cheers

干杯

#1


1  

It's only going to trigger a partial postback if the control triggering the postback is in the update panel or the control is referenced in the triggers collection of the update panel.

如果触发回发的控件位于更新面板中,或者控件在更新面板的触发器集合中引用,则它将仅触发部分回发。

Could that be the issue?

这可能是问题吗?

to use __doPostBack to trigger the partial postback - you would need to reference the updatepanel ID in the __doPostBack call e.g.

使用__doPostBack来触发部分回发 - 您需要在__doPostBack调用中引用updatepanel ID,例如

__doPostBack('btnInsideUpdatePanel', '');

It's worth noting that the first argument is the ID not theClientID. If the clientID is used then you don't get the correct event handling on postback. Check out the answer on this forum

值得注意的是,第一个参数是ID而不是ClientID。如果使用clientID,则在回发时无法获得正确的事件处理。在这个论坛上查看答案

This article gives details

本文提供了详细信息

http://encosia.com/easily-refresh-an-updatepanel-using-javascript/

http://encosia.com/easily-refresh-an-updatepanel-using-javascript/

Any help?

有帮助吗?

EDIT

编辑

I would consider changing your anchor into a Link button. The anchor html control won't raise page events in the same way as a link button (although i believe what you have done can trigger a partial postback to be fair).

我会考虑将你的锚更改为Link按钮。锚点html控件不会像链接按钮一样引发页面事件(虽然我相信你所做的事情可以触发部分回发是公平的)。

and the below link is pretty much doing what you are which might be helpful if you haven't seen it

如果您还没有看到它,那么下面的链接几乎正在做您可能会有所帮助的内容

http://weblogs.asp.net/jeffreyzhao/archive/2008/04/26/refresh-the-updatepanel-using-javascript-code.aspx

http://weblogs.asp.net/jeffreyzhao/archive/2008/04/26/refresh-the-updatepanel-using-javascript-code.aspx

Cheers

干杯