1

I have an ImageButton which, when clicked, calls a code-behind method that does some work and also changes the state of the ImageButton. I want to do a partial postback so that the entire page doesn't have to to load after clicking the ImageButton but also because I want the ImageButton as well as a Label next to it to update.

I figured I could use an UpdatePanel to accomplish this, but haven't had any luck. Here's what it looks like currently:

<asp:ScriptManager EnablePartialRendering="true" ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div class="entry-vote">
            <div class="vote-left">
                <asp:ImageButton ID="thumb" runat="server" OnClick="Cast_Vote" />
            </div>
            <div class="vote-right">
                <span class="votecount"><%# Eval("Votes.Count") %></span>
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

When I click the ImageButton, it appears to wait about five seconds and then execute the code behind.

I've never worked with partial postbacks before, so I'm kind of just flying blind here.

Anomie
  • 92,546
  • 13
  • 126
  • 145
Tyler Treat
  • 14,640
  • 15
  • 80
  • 115
  • I would recommend using jquery or javascript to update the label and imagebutton? Do you need to use a postback to accomplish it? – Robert Apr 23 '11 at 22:12
  • What is this Eval, is this inside a repeater ? – Aristos Apr 23 '11 at 22:12
  • So, apparently, the "delay" was simply due to the app running on localhost in Debug. I tried deploying it to my test server in Release mode and it works just fine. – Tyler Treat Apr 23 '11 at 22:46
  • Also sometimes setting UpdatePanel's UpdateMode to Conditional makes it do pseudo partial postback, but from my experience, update panels still posts back the entire viewstate. So if you have a listview, there's a great chance your viewstate goes back and forth on each UpdatePanel update. jQuery FTW :) – Dimitri Apr 24 '11 at 00:18
  • @Dimitri: The reason I thought I'd use an UpdatePanel is because I need to execute some business logic server-side and actually query my database. How can I achieve this using jQuery instead? – Tyler Treat Apr 24 '11 at 20:13
  • you can define a WebMethod in your pagebehind that does all the business logic and may be returns True if everything went fine (or could return the calculated value) and returns false (or throws an exception that ajax call will catch and display an alert to client) – Dimitri Apr 24 '11 at 22:57

1 Answers1

0

The delay only occurs while testing on localhost in Debug. Deploying in Release fixes the issue.

Tyler Treat
  • 14,640
  • 15
  • 80
  • 115