2011-07-25 38 views
0

我想區分usercontrol的視覺方面,但使用相同的代碼隱藏。 即我想要兩個用戶控件用.ascx文件:用戶控件使用不同的aspx,但實現相同

代碼隱藏=「Uploader.ascx.cs」繼承=「Comptech2.moduli.uploader.Uploader」

這樣我可以改變視覺方面不改變背後的代碼。

感謝 阿爾貝託

+4

好的,謝謝你讓我們知道。 – Mrchief

+0

你的問題是什麼? –

+0

男人,這不是博客,你的問題在哪裏? –

回答

2

您的用戶控件創建一個基類,最終用戶控件(* .aspx文件)從基類派生。

// base class with common functionality 
public class MyUserControlBase : UserControl { 
    // derived class will initialize this property 
    public TextBox TextBox1 {get;set;} 
    // derived class will initialize this property 
    public Button Button1 {get;set;} 

    /* some code of usercontrol */ 
} 

/* ... elsewhere ... */ 
// final class with *.aspx file 
public class MyUserControlA : MyUserControlBase { 
    protected override OnInit(EventArgs e) { 
     // "this.txtUrl" is generated from *.aspx file 
     this.TextBox1 = this.txtUrl; 
     // "this.btnSubmit" is generated from *.aspx file 
     this.Button1 = this.btnSubmit; 
    } 
} 

/* ... elsewhere ... */ 
// final class with *.aspx file 
public class MyUserControlB : MyUserControlBase { 
    protected override OnInit(EventArgs e) { 
     // "this.txtTitle" is generated from *.aspx file 
     this.TextBox1 = this.txtTitle; 
     // "this.btnOk" is generated from *.aspx file 
     this.Button1 = this.btnOk; 
    } 
} 
+1

感謝這正是我想要的 – Alberto

相關問題