如何在我的页面上显示和定位在代码隐藏中初始化的图像?
我创建了一个简单的方法来检查图像是否已获得批准并最终将其作为控件返回。但如何调用并在页面上显示呢?我在 aspx 文件中尝试过类似的方法:
<% SendImage("DKBygMiniLogo.gif", "True"); %>
这是简单的方法:
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;
}
如何实际显示图像?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以很容易地将SendImage
的结果附加到文字控件。在您的 C# 代码中:
在您的 aspx 页面中:
更新:
正如评论中正确指出的那样,您无法将子控件添加到 Literal 中,但是您可以将控件直接添加到页面中。
或将该控件添加到另一个允许添加子控件的控件,例如面板控件。
You could quite easily attach the result ofSendImage
to 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.