I want to load up a random image while a page it is loading but not sure what the syntax is for either asp:image or just img.
The files are all named the same but with a number at the end so I could do:
string Get_RandomImage()
{
Random random = new Random();
return "~/images/image" + random.Next(1, 23) + ".jpg";
}
But the image is within <ProgressTemplate> so I cant just go image.ImageURL = something in the code behind.
How can I call the random method where I am declaring the asp:Image on the aspx page?
ImageURL='<%#Get_RandomImage()%>'
does not work.
First at all you need to initialize
randomvariable outside of theGet_RandomImagemethod, make it static and change that method accessibility level toprotected. Also you can use such expressionImageURL='<%#Get_RandomImage()%>only if you callDataBindon page or image’s parent control.