UserControl(.ascx) を持つ単純な Web ページがあります。これが私のUserControlソースです
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucReportTextBox.ascx.cs"
Inherits="Intranet.UserControl.ucReport" %>
<table width="100%">
<tr>
<td>
<asp:TextBox ID="txtQuery" runat="server" Width="250px" />
</td>
</tr>
</table>
そして私のウェブページのソース
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/DefaultMasterPage.Master"
AutoEventWireup="true" CodeBehind="ComposeReport.aspx.cs" Inherits="Intranet.MasterPage.WebForm4" %>
<%@ Register Src="~/UserControl/UcReportTextBox.ascx" TagName="UcReportTextBox" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="contentHead" runat="server"/>
<asp:Content ID="Content2" ContentPlaceHolderID="contentBody" runat="server">
<table>
<tr>
<td>
<uc1:UcReportTextBox ID="ucReporttxt" runat="server" />
</td>
</tr>
//includes so many tags
</table>
</asp:Content>
私のウェブページの背後にあるコード
protected void Page_Load(object sender, EventArgs e)
{
InitComponent();
}
private void InitComponent()
{
XDocument document = XDocument.Load("ReportXML.xml");
var parameterTypes = document.Descendants("Type");
foreach (var parType in parameterTypes)
{
if (parType.Value == "string") //TODO Enumerate it !!
{
ucReporttxt.addTextBox();
}
}
}
ユーザーコントロールのコードビハインド
public void addTextBox()
{
TextBox txtBox = new TextBox();
txtBox.ID = "txtBox";
txtBox.Width = 170;
Page.Form.Controls.Add(txtBox);
}
あなたが理解しているように、私は asp.net に慣れていません。コードはテキストボックスを正しく追加しますが、テキストボックスはページの最後に追加されます。ページの最後ではない部分にテキストボックスを追加したいのですがucReportText
、どうすれば修正できますか?
ご協力いただきありがとうございます。