I’m trying to generate a grid of 1×1 pixels Images in .NET using VB.NET, using this code:
For i = 1 To 500
Dim img As New ImageButton
img.ID = "ibtn" + i.ToString
img.ImageUrl = "images/design/click.gif"
form1.FindControl("upperpanel").Controls.Add(img)
Next
Problem is that it takes a very long time to generate the HTML when I’m running this on page_load event. Can anyone help me out to speed up the rendering of the controls.
Also, I want to add Click event on each image button. How can I do that ??
Thanks
Ok, first thing to do is get the panel control once. Second, create your click method, and then add your handler. This needs to be done prior to the page load event. Use the page_Init event for creating your buttons when you need to add a handler.
As far as performance goes, getting the panel control up front will improve performance. Probably not much. Creating 500 buttons is going to take some time.