我有一个简单的用户控件,将在页面上多次显示。所以我有一个面板,它在数据集上循环,创建 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 );
}
我必须在页面的预渲染或 Onit 上执行此操作,还是有办法刷新 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)
{}
}
}