I’ve come across a bug or strage behaviour of the asp .Net control ImageButton the other day.
If you don’t specify a value for the attribute “ImageUrl”, the server will do an access to your default page. To highlight this I’ve created a small project sample that you can find here.
This project contains a default.aspx page, and 2 pages: one with an ImageButton control with attribute “ImageUrl” set (page1.aspx), the other one without the attribute (page2.aspx).
If you lanch the web application: you will see in the output:
Goes through _Default.Page_Load with IsPostBack:False
Go to the page1.aspx page by clicking on button “Page 1″, you will see in the output:
Goes through _Default.Page_Load with IsPostBack:True
Goes through Page1.Page_Load with IsPostBack:False
Now click on the back button of your explorer, and go to page2.aspx by clicking on button “Page 2″, you will see in the output:
Goes through _Default.Page_Load with IsPostBack:True
Goes through Page2.Page_Load with IsPostBack:False
Goes through _Default.Page_Load with IsPostBack:False
You can notice the access to default page. To avoid useless access to the default page, even if you want to setup the ImageUrl property of the control programatically, set a value in the page.