简体   繁体   English

替换Asp.net后面代码中的图像

[英]Replace an image in code behind for Asp.net

I have a page, which is called from 2 different functions. 我有一个页面,从2个不同的函数调用该页面。 For each function, the page has to be display different image. 对于每个功能,页面必须显示不同的图像。 I have 2 images. 我有2张图片。

On the aspx page, code is like this. 在aspx页面上,代码是这样的。 Please help me out how to display different image for different functions!! 请帮助我如何显示不同功能的不同图像! Thanks Guys!! 多谢你们!!

Assuming you have an image on your ASPX page like this 假设您在ASPX页面上有这样的图像

<asp:Image id="myImage" runat="server" />

You can dynamically change the ImageUrl property of the image on the server-side like: 您可以在服务器端动态更改图像的ImageUrl属性,如下所示:

protected void Page_Load(object sender, EventArgs e)
{
    // Your logic to detect which image to display goes here
    var imageUrl = GetMyImageUrl();

    myImage.ImageUrl = imageUrl;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM