1
votes

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(MyUserControl);

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

Thanks in advance.

2

2 Answers

1
votes
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";
}
0
votes

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