[英]Find Image Control from user control
我真的是ASP和C#的新手。 我有一个带有两个单选按钮的用户控件,还有一个图像控件。 我想在单击按钮时动态加载此控件,同时将ImageURL赋予图像控件。 FileUpload在aspx页面上。 谁能帮我??
控制MyUserControl = LoadControl(“ MyControl.ascx”); PlaceHolder1.Controls.Add(MyUserControl);
我能够加载用户控件。 现在如何提供imageURL。
提前致谢。
public partial class MyUserControl:UserControl
{
public string ImageUrl
{
set{ image1.ImageUrl=value;}
get{return image1.ImageUrl;}
}
}
var ctrl=LoadControl("MyControl.ascx") as MyUserControl;
if(ctrl!=null)
{
ctrl.ImageUrl = "image.mpg";
}
公开公开MyControl.ascx中的图像URL,然后将MyUserControl强制转换为用户控件并分配图像示例:
Control MyUserControl1 = LoadControl("MyControl.ascx");
MyUserControl temp = (MyUserControl) MyUserControl1;
temp.ImageURL = "urlhere.jpg";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.