Getting a full postback from within an UpdatePanel without using a PostbackTrigger

Published Thu, Feb 1 2007 16:23

Remember those old movies where there was someone bragging and saying something like "hey, look! no Hands!" while riding a bike (or something like that)? Well, I'm going to do something similar :) Look at me: only one hand (sorry, but it looks like Vista's voice recognition isn't still working out as it should and, that being the case, I do need one hand to write :)), no postback triggers, a link button within an UpdatePanel and a full postback. Don't believe me? Run this code:

<%@ Page Language="C#" %>
<html>
 <head runat="server">
    <title>Untitled Page</title>
 </head>
<body>
  <form id="form1" runat="server">
    <asp:ScriptManager id="manager" runat="server" />
         <asp:UpdatePanel runat="server" id="panel">
              <ContentTemplate>
                <asp:LinkButton runat="server" Text="Full postback" />
              </ContentTemplate>
          </asp:UpdatePanel>
  </form>
</body>
</html>

Ok, I cheated :). the truth is that I'm using both hands (which means that you'll be getting a full postback with the previous sample).

Next question: why? well, simply look at the code you're getting on the client (only  the LinkButton control):

<a href="__doPostBack('ctl03','')">Full postback</a>

Noticing anything strange? I do! note that even though the server control generates an ID it will only be inserted on the client HTML control if you explicitly set the ID porperty on the server control. So, if you add the ID to the control everything works ou as expected. If you don't, then the PageRequestManager won't be able to find the control (remeber, it doesn't have an ID and all the work that is done is by the PageRequestManager is based on finding the control through the ID)

Good news to the AJAX team: this isn't really your fault!

Bad news to the ASP.NET team: this is your fault!

If you really think about it, the AJAX team can be seen as subset of the ASP.NET team :) ...

 [Update: I've dropped the javascript prefix from the previous excerpt ]

Filed under:

Comments

# Lucian N said on Thursday, February 01, 2007 5:14 PM

Luis,

I need your help -- I believe both of your hands :).

Please comment this scenario: I want AllowCustomErrors="false" in ScriptManage and <customErrors mode="Off"/> in web.config because I lilke to custom handle the errors in global.asax (or in a http module class) based on a custom exception class I built on top of ApplicationException.

Made a few tests on current MS AJAX RTM and it looks like there is no way to make ScriptManager to skip its verifications. Is there something I should know, or this scenario is just not possible yet?

Thanks,

Lucian N

# Luis Abreu said on Thursday, February 01, 2007 5:25 PM

Hello.

Does this help (it's old an i haven't tried it in the final release...):

http://msmvps.com/blogs/luisabreu/archive/2006/10/31/Handling-errors-globally.aspx

# Luis Abreu said on Thursday, February 01, 2007 5:25 PM

Hello.

Does this help (it's old an i haven't tried it in the final release...):

http://msmvps.com/blogs/luisabreu/archive/2006/10/31/Handling-errors-globally.aspx

# Lucian N said on Friday, February 02, 2007 4:33 AM

Luis,

Thanks for replying.

I took Joao's approach and is working fine.

There is a problem with Server.Transfer(...) who cannot stop current page processing and ends with a javascript alert window. Still Request.Redirect(...) to error page saved the day, but with some downsides (and I'm not sure I like that :)).

The idea is -- as you pointed out -- to move the error handling scope from application to page. Global.asax or a http module is a good place to do that.

Great help!

Thanks,

Lucian

# Luis Abreu said on Friday, February 02, 2007 5:16 AM

Hello again.

Lucian, you'll never be able to use Server.Transfer because doing that will return the HTML from the destination page and the client side is expecting a predefined message format (that's why you can't use server.transfer). on the other hand, when you do a response.redirect, the response is "intercepted" in the server side by the scriptmodule and it'll transform the response so that the client side object understands the response. that's why response.redirect rowks and server.transfer doesn't.

# Jim Cheseborough said on Monday, March 26, 2007 2:22 PM

Does not work for me (I need the full postback!).

Maybe it's do to the fact this control is nested in two usecontrols?

Please help!

Thanks!

Jim *AT* Cheseborough.com

# HowerS said on Friday, July 13, 2007 12:53 PM

Your Brilliant... Saved me hours of trying to get this fixed.  Thanks

# SoSoSO said on Tuesday, November 06, 2007 9:07 AM

So a postbacktrigger is there just to make sure controls within an update panel can do a full postback?  Is that what I'm understanding?

# Mike said on Tuesday, March 18, 2008 6:01 PM

Thank you. I spent two hours on this before I found this post.

# b2b said on Friday, July 11, 2008 7:38 PM

have the same issue...

# hook said on Tuesday, June 16, 2009 8:09 AM

Thanks for the article.  This solved my problem

# Emily said on Monday, December 28, 2009 10:57 AM

Thank you so much! This helped solve a very frustrating set of issues I was having with my site design.

# th said on Thursday, June 16, 2011 1:07 PM

I have a similar issues i've been trying for days to solve, it's the same issue, however the difference is, i'm creating the linkbuttons dynamically inside the update panel.  If i don't add an id to them i get a full post back, if i do add an id to them i get a javascript runtime error "This object doesn't support the property or method" this is extremely frustrating, does anyone have any advice they can give asap?  Note:  the only reason i'm using LinkButton is because for some reason ImageButton doesn't fire anything off whatsoever inside an update panel, very frustrating.  

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above:  

Search

This Blog

Tags

Community

Archives

Syndication

Email Notifications

News




  • View Luis Abreu's profile on LinkedIn


    Follow me at Twitter

    My books

    Silverlight 4.0: Curso Completo

    ASP.NET 4.0: Curso Completo

    Portuguese LINQ book cover

    Portuguese ASP.NET 3.5 book cover

    Portuguese ASP.NET AJAX book cover

    Portuguese ASP.NET AJAX book cover