如何从用户控件中找到图像控件

如何从用户控件中找到图像控件

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

问题描述

我真的是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?

推荐答案


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


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

08-04 22:40