如何从用户控件中找到图像控件 [英] How do I find an Image control from the User-control

查看:81
本文介绍了如何从用户控件中找到图像控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的是ASP和C#的新手.我有一个用户控件,其中有两个单选按钮[Delete,Cover]和一个图像控件.我想在单击按钮时动态加载此控件,同时将ImageURL赋予图像控件. FileUpload 在aspx页面上.谁能帮我? :confused:

Hi, I am really new to ASP and C#. I have a User control which has two Radio Buttons [Delete, Cover], and an Image control. I want to load this control dynamically on the 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? :confused:

public partial class ImageDynamic : System.Web.UI.Page
{
    protected void Button2_Click(object sender, EventArgs e)
     {
        Control MyUserControl = LoadControl("MyControl.ascx");
        PlaceHolder1.Controls.Add(MyUserControl);
    }
}



使用上面的代码行,我可以加载用户控件.现在如何设置ImageURL?



Using the above lines of code I was able to load the user control. Now how do I set the ImageURL?

推荐答案

您好

您可以在用户控件中使用FindControl方法来找到图像控件.

就像MyUserControl.FindControl(您的图像控件ID")

谢谢
希望这对您有帮助
Hi

You can use FindControl method in the user control to find the Image Control.

Like MyUserControl.FindControl("Your Image Control Id")

Thanks
Hope this helps


Image MyImage = (Image)MyUserControl.FindControl("ImageControlID");
MyImage.ImageUrl = "ImagePath";


这篇关于如何从用户控件中找到图像控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆