开发者

Find Image Control from user control

开发者 https://www.devze.com 2023-02-06 21:04 出处:网络
I am really new to ASP and C#. I have a User control which has Two Radio Buttons, and and Image 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

精彩评论

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

关注公众号