2011-09-27 78 views

回答

2

嘗試,

Control control=LoadControl("~/UserControlFile.ascx"); 

我發表你的線程答案:

  1. How to load a web usercontrol from a physical path rather than a virtual path
  2. Loading web user controls from blob storage in asp.net

編輯:

這裏是位於App_Code文件

public class TestControl : UserControl 
{ 
    public TestControl() { } 
    public TestControl(string message) 
    { 
     SayHello = message; 
    } 
    public string SayHello { get; set; } 

    public override void RenderControl(HtmlTextWriter writer) 
    { 
     base.RenderControl(writer); 
     writer.Write(SayHello); 
    } 
} 

和代碼來加載一個TestControl.cs /創建一個控制對象:

TestControl tc = (TestControl)LoadControl(typeof(TestControl), new object[] { "Hello Buddy" }); 
+0

這是使用LoadControl的第一過載正確?我問我可以用第二次超載來做嗎? –

+0

請看看這個主題 - http://stackoverflow.com/questions/240850/asp-net-usercontrol-loadcontrol-issue – adatapost

+0

嗨,我已經在線程中添加了一條評論在asp中從blob存儲中加載web用戶控件.net。你能看一次嗎? –

相關問題