There are a lot of discussions about why the Page events get called twice or even multiple times. Most the solutions from Google search suggested to set AutoEventWireup
to false
. By default, it is true
. Is it really helpful? For sure, a lot of people will disagree. Me either. The solution of AutoEventWireup
doesn't stand for all cases. To me, most of the time, this issue is related to image resource.
Consider the following HTML code in the ASP.NET page markup.
<img src="" id="img1" alt="an image" style="display:none" />
The HTML is valid but it is the trouble maker in ASP.NET Web form, which causes the page events being called twice because the src
attribute is empty. Removing the src
attribute entirely will fix the problem.
Let's consider another image related scenario. What if you want to set a background color in a table cell but mistakenly put background
attribute instead of background-color
?
<TD background="#008080">
In this case, page events are also being called twice. But if HTML color name is used, everything will work fine. Thus the following HTML code won't cause trouble although it is not correct.
<TD background="Teal">
I am not quite sure how or when CalliHelper.EventArgFunctionCaller
will bind the above scenarios to the page events. None of them are declared to run as server
. But I do know that if the page events are being called twice, the first thing I will check is the markup, especially those HTML codes related to image resource.