我對ASP和C#真的很陌生。 我有一個用戶控件,它有兩個單選按鈕,和圖像控件。 我想單擊按鈕動態加載此控件,同時將ImageURL提供給圖像控件。 FileUpload位於aspx頁面上。 任何人都可以幫助我嗎?從用戶控件查找圖像控件
控制MyUserControl = LoadControl(「MyControl.ascx」); PlaceHolder1.Controls.Add(的MyUserControl);
我能夠加載用戶控件。 現在如何提供imageURL。
在此先感謝。
我對ASP和C#真的很陌生。 我有一個用戶控件,它有兩個單選按鈕,和圖像控件。 我想單擊按鈕動態加載此控件,同時將ImageURL提供給圖像控件。 FileUpload位於aspx頁面上。 任何人都可以幫助我嗎?從用戶控件查找圖像控件
控制MyUserControl = LoadControl(「MyControl.ascx」); PlaceHolder1.Controls.Add(的MyUserControl);
我能夠加載用戶控件。 現在如何提供imageURL。
在此先感謝。
揭露圖片網址你MyControl.ascx公共 然後鑄造的MyUserControl你的用戶控件和指定圖像 例如:
Control MyUserControl1 = LoadControl("MyControl.ascx");
MyUserControl temp = (MyUserControl) MyUserControl1;
temp.ImageURL = "urlhere.jpg";
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";
}
我添加了你的代碼,但它給出了一個錯誤 無法找到類型或名稱空間名稱'MyUserControl'(你是否缺少使用指令或程序集引用?) – Sayed 2011-01-27 14:24:12
嗨約翰·肯尼迪, 我怎麼能暴露圖片的網址?? – Sayed 2011-01-27 14:24:38