I have created a simple method to check if an image has been approved and finally returns it as an control. But how do i call and show it on the page? I’ve tried something like this in the aspx-file:
<% SendImage("DKBygMiniLogo.gif", "True"); %>
Here is the simple method:
protected Image SendImage(object Image, object Approved)
{
bool approved = Convert.ToBoolean(Approved);
Image img = new Image();
if (approved)
{
img.ImageUrl = "~/images/Ads/" + Image.ToString();
img.Visible = true;
}
else
{
img.ImageUrl = "~/images/Ads/" + Image.ToString();
img.Visible = false;
}
return img;
}
How do I actually show the image?
You could quite easily attach the result ofSendImageto a literal control.In your C# code:
In your aspx page:
UPDATE:
As correctly pointed out in the comments, you can’t add child controls to a Literal however you can add the control directly to the page.
or add the control to another control that does allow child controls to be added such as a Panel control.