我想将<asp:image>从我的代码后台添加到页面上。我的网站上的用户将上传X数量的图片,我不想在图片上传之前添加<asp:images>。
我想添加<asp:image>的原因是为了向用户显示已经上传的图片。
如何做到这一点?
我见过使用占位符控制器,但是当变量必须不同时,如何使用它呢?对于每个上传的图像应该添加到网站上。
发布于 2012-11-05 20:08:35
为此,您可以创建一个新的Image对象变量,然后适当地分配它的属性,然后将图像附加到页面上的现有对象。
Image myImg = new Image();
myImg.ImageUrl = "path_of_the_image.jpg";
myImg.Visible = true;
Panel1.Controls.Add(myImg); //You can attach the image to any control on your page或者类似的:
this.Controls.Add(myImg); //Incase you wanted the image on your page controls
Label1.Controls.Add(myImg); //Incase you wanted the image to appear in a certain label但是,此对象不会超过您执行的代码的生命周期。这意味着,您稍后将无法与此对象交互,因为它是在Page_Init的作用域之后定义的。如果您希望动态添加此图像,然后能够与其交互,则应在Page_Init事件期间添加此图像。
https://stackoverflow.com/questions/13231423
复制相似问题