目前我有这个:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs" Inherits="Drawing.Usercontrols.WebUserControl2" %>
<asp:Image ID="Image1" runat="server" alt="Image Not Found" ImageUrl="~/images/k8up7l1i.bmp"/>
在 webUserControl2.ascx 页面中。
在 WebUserControl2.ascx.cs 页面中,找到了所有逻辑。在那里生成一个Image,然后保存到一个路径(C:\Work Drawing\Drawing\Drawing\images) 其中:
string thisPathName = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/" + randomFileName);
我的问题是,我可以从 asp 页面调用方法“getPathName()”(ImageUrl 所在的位置,而不是静态 URL)。所以每次我调用它时,新图像都会显示在浏览器中,并带有在 C# 代码中生成的路径名?
如果问题不清楚,请通知我。
最佳答案
答案是肯定的,你可以。
假设您在代码后面有这个函数:
public string getPathName(){
return "my_image_path.jpg";
}
这样,您可以采用以下形式:
<img alt="Image Not Found" src="<%=getPathName()%>"/>
好了。你从后面的代码中得到你的图像路径。
祝你好运。
关于c# - asp.net c# 中的动态 imageURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29212447/