开发者

Find Image Control from user control

I am really new to ASP and C#. I have a User control which has Two Radio Buttons, and and Image control. I want to load this control dynamically on click of a button and at the same time give ImageURL to the image control. FileUpload is on the aspx page. Can anyone help me??

Control MyUserControl = LoadControl("MyControl.ascx"); PlaceHolder1.Controls.Add(MyUserCon开发者_JAVA技巧trol);

I was able to load the user control. Now how to provide the imageURL.

Thanks in advance.


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


Expose the image URL in your MyControl.ascx as public Then casting MyUserControl to your usercontrol and assign the image example :

Control MyUserControl1 = LoadControl("MyControl.ascx");
MyUserControl temp = (MyUserControl) MyUserControl1;
temp.ImageURL = "urlhere.jpg";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜