2011-07-25 10 views
0

ユーザーコントロールの視覚的な側面を区別したいが、同じコードビハインドを使用する。 つまり、私はた.ascxファイル内に2人のユーザーコントロールをしたい:異なるaspxで同じインプリメンテーションのユーザーコントロール

分離コード=「Uploader.ascx.cs」継承=「Comptech2.moduli.uploader.Uploader」私はせずに視覚的な側面を変更することができます。このように

コードを変更する

おかげ アルベルト

+4

Googleからお知らせいただきありがとうございます。 – 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

関連する問題