FormView がある UserControl があります。
フォーム ビューには InsertItemTemplate しかありません (他には何も必要ありません)。
<irt:FormView ID="FormViewInsertEvent" DefaultMode="Insert" runat="server" DataKeyNames="EVENT_ID"
DataSourceID="SqlDataSourceIocEvents">
<InsertItemTemplate>
//Some form elements (text boxes and labels etc.) which are common
<%if (CustomContent != null)
{ %>
<hr />
<asp:PlaceHolder runat="server" ID="PlaceHolderCustomContent"></asp:PlaceHolder>
<%} %>
// Link buttons with insert command
</InsertItemTemplate>
</irt:FormView>
コードビハインドは次のようになります。
public partial class EventControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (CustomContent != null)
{
Control ph = FormViewInsertEvent.FindControl("PlaceHolderCustomContent");
CustomContent.InstantiateIn(ph);
}
}
[
DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
TemplateInstance(TemplateInstance.Single),
Browsable(false)
]
public ITemplate CustomContent {
get;
set;
}
}
呼び出し元 (ページ) には、次のようなものがあります (データソースを UC に渡し、コードビハインドから FormView のデータソースを設定しています。これには問題はありません):
<irt:EventControl ID="EventControl" runat="server" DataSourceID="SqlDataSourceIocEvents">
<CustomContent>
Custom Field:
<asp:TextBox ID="TextBoxCustomField" runat="server" Text='<%# Bind("CustomField") %>' />
</CustomContent>
</irt:EventControl>
私の問題は; リンク ボタンをクリックして PostBack すると、カスタム コンテンツ、つまりテンプレート フィールド内に入力したコンテンツが消えます。
asp:PlaceHolder を FormView.InsertItemTemplate の外に配置しても問題はありません。しかし、それは私が必要とするものではありません。
ポストバック後も保持するには、InsertItemTemplate 内の ITemplate が必要です。テンプレートが PlaceHolder のコントロール リストに追加されているように見えますが、PreRender と Render の間のどこかで、これらのコントロールが削除されています。
何か案は?
ありがとうナンドゥン