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";
精彩评论