Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未填充的动态控件_C#_Asp.net - Fatal编程技术网

C# 未填充的动态控件

C# 未填充的动态控件,c#,asp.net,C#,Asp.net,我有一个简单的用户控件,它将在页面上显示多次。所以我有一个面板,在数据集上循环,创建UC,填充一个文本框和一个复选框,然后将其添加到面板中 面板添加UC,但文本框值和复选框均未更改 foreach (Issue iss in Case.Issues) { Comments comment = (Comments)LoadControl("~/UserControls/Comments.ascx"); comment .ID = "Comment" + iss.IssueDetai

我有一个简单的用户控件,它将在页面上显示多次。所以我有一个面板,在数据集上循环,创建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 -->

从您所展示的内容来看,没有什么明显的错误,但是在设置值之前可能会发生空引用异常。因为try/catch块是空的,所以您不会知道它。使用空的try/catch从来都不是一个好主意,因为您不知道是否发生了异常。

能否向我们展示UserControl的代码和标记?完成。这只是一个很小的问题。当然,你说的是对的,目前正在开发中。但推翻OnInit已经成功了。所以现在我调用在调用base.Oninit(e)之前添加UC的函数。
 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)
                {}
            }
        }