Friday, September 23, 2011

__doPostBack causing Screen Flicker even when set as Asyncpostbacktrigger

Ran into a good one today that made me to start a BLOG.  I run into issues all the time that require fixes.  Sometimes, you can find solutions on the web.  Sometimes, you can't.

I always felt like I should give back to the community that I extract so much from.  So, here's one that I had to reason through with just a little help.

I had a scenario where I needed a button to exist but not allow the user to click it.  The reason is that I needed some javascript to perform a __doPostBack() using that button so that the ASP.NET page would fire its event on post back.  However, I do this in response to some other user actions handled by javascript.  Thus, to prevent the user from clicking the button, I set the visibility property of the button to false.

<asp:button id="someButton" runat="server" visible="false" />

So, my javascript would fire the event correctly.

__doPostBack('someButton',null);

And my ASP.NET page would capture the event correctly.

The problem I ran into though was that even though my button was inside an UpdatePanel, I would still get screen flicker.  I tried adding the button as an Asyncpostbacktrigger as the recommendation of many on-line searches.

<asyncpostbacktrigger controlid="someButton" />

The screen flicker continues.  I'm annoyed at this point.  How could the event be firing, be being captured, be an asyncpostbacktrigger, and still causing screen flicker?

The answer turns out that the UpdatePanel triggers can't "see" a control that has its visibility set to false, most likely because the control never makes it to the page.  Thus, it performs a full postback.

The simple solution?

<asp:button id="someButton" runat="server" visible="true" style="display : none;">

Solved!

2 comments:

  1. THANK YOU!! Like you I was searching around the net and couldn't find a solution.

    ReplyDelete
  2. Awesome. Glad a search engine actually found this. :)

    ReplyDelete