Monday, May 2, 2011

LinkButton inside ListView within UpdatePanel cause full postback

Hi Friends,

Today I was creating a listing page with ASP.Net 4.0. I wanted below items on the page

  • A result for my search, I have used ListView for it
  • Inline editing for 1-2 column of my list
  • Edit & Update/Cancel button
    • Generally I am using ImageButton to display Edit/Update/Cancel buttons
    • This time I thought lets use LinkButton, I have also used AjaxControlToolkit’s HoverMenu extender.
  • Apply Ajax on the page, I have placed ListView inside UpdatePanel and set ChildrenAsTriggers as true.

Ok, now I have implemented all the items I required on the page. When I clicked on the Edit link, I was surprised, LinkButton was causing Synchronized Postback (Full page postback). There are many causes where your page do full postback like

  • Page HTML have some unclosed tags
  • there is some JavaScript error
  • You have generated control dynamically but forgot to assign ID to your control

Well I have verified all of them but my problem was different, I was totally confused that how to overcome this issue “I have a update panel, have ChildrenAsTriggers true, Ajax framework is loaded, still my LinkButton causing full postback”

I have given a try, I have converted my LinkButton to Button, everything works fine and page is now doing Partial postback. Now I knew that there is a problem with LinkButton.

By lots of trial and error I figured it out, we need to add

<pages clientIDMode="AutoID"></pages>

ClientIDMode specifies, how will ASP.Net 4.0 generates the id attribute for rendered HTML controls/elements. In previous version of ASP.Net there was not any concept of client id generation, but it was similar to AutoID configuration we have set. Currently default settings for client ID is Predictable.

Hope this will help you to solve your problem

Nirav

10 comments:

  1. Büyüksün reis!
    You saved my hours. Thanks!

    ReplyDelete
  2. THANK YOU THANK YOU and thank you!!

    I have been struggling with this for ages and it was the clientidmode. With me i only had this problem when a used the ajax control toolkit!! but this resolved it

    ReplyDelete
  3. Waoooooo! i spend hours to figure it out but after reaching your post it remains only to few seconds and all over.

    thanx a lot.........

    ReplyDelete
  4. Hi,

    Thanks for the post, saved me a lot of time.

    I did some playing on a similar setup (linkbutton in an asp:repeater), and I found that you can add the ClientIdMode to the repeater if you wish, which reduces it's scope.

    Might be handy if you have code elsewhere that works better with a different client ID Mode.

    Cheers

    Greg.

    ReplyDelete
  5. I couldn't figure out why older versions of the AjaxControlToolkit would work fine with my LinkButtons and not cause full postbacks, while the newer versions of the AjaxControlToolkits would. Seems like a lot of people are having this same issue and no one has posted a fix or reason for it except you. Kudos to you for saving a lot of us from wasting precious hours on our web projects.

    ReplyDelete
  6. really it is awesome...thanks dud save lot of time!!!!!!!

    ReplyDelete
  7. thanx a ton,It works great.Appreciated

    ReplyDelete

Comments posted on ASP.Net Ajax Tutorials Blog are moderated and will be approved only if they are on-topic and not abusive. Please email me or my team for tech-support or blogging related questions. Avoid including website URLs in your comments - Thanks Author