ASP .NET WebPart, Control Or Page loads twice problem

Another issue hit me today and spent some time debugging it. As the title says my control events all launched twice. This caused problems to my code logic and also it is an unnecessary performance hit to do something twice when one rendering pass is what is enough.

The problem was due to the <asp:image control inside my SharePoint 2010 Visual Webpart. For some reason(I’m gonna say a bug in MS code, it seems like it) if you did not set the image URL of the control while it is created OR defined(lets say on the ASCX side my webpart) you will suffer from double loading.

Of course this did not solve my problem entirely until I decided to ditch the <asp:image control and replace it with a HTML server side control <img. NOTICE that I still had to set the img src attribute to some location while defining the control.

Example of the control definition:

<img src=”#” id=”iBlogImage” runat = “server”/>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s