1

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.

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

So here is my aspx side code:

<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:

        <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')**">
LuxuryWaffles
  • 1,518
  • 4
  • 27
  • 50

1 Answers1

2

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('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

This article gives details

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).

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

Cheers

Crab Bucket
  • 6,219
  • 8
  • 38
  • 73
  • 1
    I get a nervous tick whenever I have to maintain code that has UpdatePanel controls. Invariably, people see how "easy" it is to use them and start putting way too many of them on a page. – Karl Anderson Jun 22 '13 at 15:32
  • 1
    they are totally abused. I have seen terrible usage - multiple nesting, wrapping vast amounts of content etc.. But for certain things they are useful. Just must only be used for good and never evil – Crab Bucket Jun 22 '13 at 15:33
  • 1
    @BloopieBloops - no offense meant, I was just venting, because I have worked on so many projects where UpdatePanels became the golden hammer and every problem was a nail. – Karl Anderson Jun 22 '13 at 16:15
  • None taken @Karl, it's just like advice, anyways tried __doPostBack('UpdatePanel1', ''); . Still full update, why is it Updatepanel instead of the button? – LuxuryWaffles Jun 22 '13 at 16:34
  • ah - i think you are right - Sorry. - a notional button inside of the update panel does the triggering. Your modalboxStaff link would need to be inside the panel or in trigger collection. To get it workign I would just try with a button inside of the panel -you know (i know) that should work (as a temp let's see if this works measure) – Crab Bucket Jun 22 '13 at 17:00
  • @CrabBucket, for replying. Does the page gets scrolled to the top after partial updates? – LuxuryWaffles Jun 23 '13 at 04:45
  • 1
    sorry it doesn't. This link may help http://stackoverflow.com/questions/6583501/maintain-scroll-position-after-async-postback-from-update-panel – Crab Bucket Jun 24 '13 at 08:12