我有一個簡單的用戶控件,它將在頁面上多次顯示。所以我有一個循環數據集的面板,創建UC,填充文本框和複選框,然後將其添加到面板。未安裝動態控件
面板添加UC但無論是文本框的值,也不該複選框被改變......
foreach (Issue iss in Case.Issues)
{
Comments comment = (Comments)LoadControl("~/UserControls/Comments.ascx");
comment .ID = "Comment" + iss.IssueDetail.quality_control_issue_id.ToString();
comment .Populate(iss);
QCComments_list.Controls.Add(comment);
}
我一定要做到這一點的預渲染或頁面在它身上還是有令人耳目一新的方式UC的控制?
以下是UC標記。很簡單。
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ROI_Comments.ascx.cs" Inherits="QualityControl_UserControls.ROI_Comments" %>
<!-- Field -->
<div id="ROI_Comment_DIV" class="field">
<label>Corrections</label>
<input type="text" runat="server" id="comtxt" name="comtxt" />
<asp:CheckBox ID="issue_critical" runat="server" Text="Critical" />
<asp:Button runat="server" id="SaveButton" Text="Add Comment" OnClientClick="SaveComment(this);return false;" />
<asp:Button runat="server" id="ROICancelButton" Text="Cancel" OnClientClick="return false;" />
<asp:HiddenField runat="server" ID="hIssueID" />
</div>
<!-- /Field -->
和的.cs
public partial class ROI_Comments : System.Web.UI.UserControl
{
public ROI_Comments()
{
}
public void Populate(cQuality_Control_Issue _comment)
{
try
{
hIssueID.Value = _comment.IssueDetail.quality_control_issue_id.ToString();
comtxt.Value = _comment.IssueDetail.quality_control_issue_description;
comtxt.Disabled = true;
issue_critical.Checked = _comment.IssueDetail.quality_control_issue_critical;
issue_critical.Enabled = false;
ROICancelButton.Text = "Delete";
}
catch(Exception ex)
{}
}
}
你能告訴我們的代碼和UserControl的標記嗎? – Kenneth
完成。它只有一個小的UC – user2807494