asp.net c#中的动态imageURL [英] Dynamic imageURL in asp.net c#
问题描述
目前我有这个:
<%@ 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.cs页面中,找到所有逻辑。在那里生成一个图像,然后保存到一个路径(C:\Work Drawing \Drawing \Drawing \ images)
其中:
In WebUserControl2.ascx.cs page, all of the logic is found. An Image is generated there, and then saved to a path (C:\Work Drawing\Drawing\Drawing\images) where:
string thisPathName = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/" + randomFileName);
我的问题是,我可以从asp页面调用方法getPathName()(其中ImageUrl是,而不是静态URL)。因此,每当我调用它时,新图像将显示在浏览器中,并在c#代码中生成该路径名?
My question is, can i call a method "getPathName()" from the asp page (where ImageUrl is, instead of a static URL). So each time i call it, the new image will be displayed in the browser with that pathname generated in the c# code?
如果问题不清楚,请通知我。
Please notify me if the question was unclear.
推荐答案
答案是,是的,你可以。
the answer is Yea , you can .
让我们假设你在代码后面有这个函数:
let's assume you have this function in code behind:
public string getPathName(){
return "my_image_path.jpg";
}
你可以在表格中填写:
<img alt="Image Not Found" src="<%=getPathName()%>"/>
然后你就去了。你从后面的代码中得到你的图像路径。
and there you go . you get you'r image path from the code behind .
祝你好运。
这篇关于asp.net c#中的动态imageURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!