私はASP.NETカスタムコントロールに取り組んでおり、現在、同じページ/フォーム.netでカスタムコントロールを複数回使用するで尋ねられたようないくつかの問題に直面しています。
ここでわかる違いは、私のコントロールにはプロジェクトに埋め込まれた JavaScript と画像があり、単一の dll としてコンパイルされることです。
名前空間CustomControl
には次のものがあります。
public class myControl: TextBox
{
protected override void OnPreRender(EventArgs e)
{
string strJS = "//my Javascript initialization codes";
base.OnPreRender(e);
CustomControl.myControl.Include_ScriptFile(Page.ClientScript); // Refers external JS file added as a web resource in the AssemblyInfo file
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CreateControl", strJS, true); // add the JS initialization code for the control on the page
}
}
他のプロジェクトの ASPX ページのコード (2 つのプロジェクトは既に参照されています)
<cc1:myControl ID="cControl1" runat="server" Width="100%"/>
<cc1:myControl ID="cControl2" runat="server" Width="100%"/>
最初のコントロールは適切にレンダリングされますが、2 番目のコントロールはレンダリングされません。2 番目のコントロールの JS 初期化が追加されておらず、2 番目のコントロールが廃止されていることを firebug で確認できます。では、2 番目のコントロールにも初期化コードを追加するにはどうすればよいでしょうか。