从用户控件中查找图像控件

时间:2011-01-27 13:51:41

标签: c# asp.net user-controls

我是ASP和C#的新手。 我有一个用户控件,它有两个单选按钮和图像控件。 我想在点击按钮时动态加载此控件,同时将ImageURL提供给图像控件。 FileUpload位于aspx页面上。 任何人都可以帮助我吗?

Control MyUserControl = LoadControl(“MyControl.ascx”); PlaceHolder1.Controls.Add(的MyUserControl);

我能够加载用户控件。 现在如何提供imageURL。

提前致谢。

2 个答案:

答案 0 :(得分:1)

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";
}

答案 1 :(得分:0)

将MyControl.ascx中的图片网址公开为公开 然后将MyUserControl转换为您的usercontrol并分配图像 例如:

Control MyUserControl1 = LoadControl("MyControl.ascx");
MyUserControl temp = (MyUserControl) MyUserControl1;
temp.ImageURL = "urlhere.jpg";
相关问题