LA.NET [EN]

Feb 01

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 ]

13 comments so far

  1. Lucian N
    11:14 pm - 2-1-2007

    Luis,
    I need your help — I believe both of your hands :).

    Please comment this scenario: I want AllowCustomErrors=”false” in ScriptManage and 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

  2. Luis Abreu
    11:25 pm - 2-1-2007

    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

  3. Luis Abreu
    11:25 pm - 2-1-2007

    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

  4. Lucian N
    10:33 am - 2-2-2007

    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

  5. Luis Abreu
    11:16 am - 2-2-2007

    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.

  6. Jim Cheseborough
    7:22 pm - 3-26-2007

    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

  7. HowerS
    5:53 pm - 7-13-2007

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

  8. SoSoSO
    3:07 pm - 11-6-2007

    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?

  9. Mike
    11:01 pm - 3-18-2008

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

  10. b2b
    12:38 am - 7-12-2008

    have the same issue…

  11. hook
    1:09 pm - 6-16-2009

    Thanks for the article. This solved my problem

  12. Jeff Tomlinson
    9:02 pm - 12-8-2009

    A thousand thank yous for this.

  13. Emily
    4:57 pm - 12-28-2009

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

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>