更新母版页中的图像
我在主页上有一个图像控件(用于徽标),如下所示:
<asp:Image ID="imgLogo" ImageUrl="~/Images/logo.jpg" runat="server" />
我允许我的用户上传他们自己的徽标。因此,在他们上传徽标的页面上,我想用新上传的徽标替换现有徽标。我尝试了以下方法,但没有一个起作用:
1)做了 Response.Redirect 返回同一页面,但不起作用。
2)图像上传完成后尝试以下代码,但仍然不起作用:
Image imgLogo = (Image)Master.FindControl("imgLogo");
imgLogo.ImageUrl = "~/Images/newLogo.jpg";
I have an Image control (for logo) on the master page as follows:
<asp:Image ID="imgLogo" ImageUrl="~/Images/logo.jpg" runat="server" />
I am allowing my users to upload their own logos. So on the page where they upload their logo I want to replace the existing logo with the newly uploaded logo. I tried the following but none of them worked:
1) Did a Response.Redirect back to the same page and it didn't work.
2) Tried the below code after the image upload is complete and even this didn't work:
Image imgLogo = (Image)Master.FindControl("imgLogo");
imgLogo.ImageUrl = "~/Images/newLogo.jpg";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试结合使用这两种方法:执行 Response.Redirect 并在页面加载时替换 ImageUrl。
Try combining both approaches: do a Response.Redirect and replace ImageUrl on page load.
在我的机器上工作正常 - 确定文件最终位于您认为的位置吗?
或者,操作完成后您正在做什么?您是否在 OnLoad 或类似中设置 ImageUrl ?您在执行此操作时是否检查是否处于回发状态?
代码:
Works okay on my machine - sure the file is ending up where you think it is?
Alternatively what are you doing after the action is complete? Are you setting ImageUrl in OnLoad or similar? Are you checking that you're not in a postback when doing so?
Code: