我在用户控件中有一个文本框。我动态地创建了这个用户控件并加载到占位符中。
但是当我尝试为文本框赋值时,我提出了下一个错误:
Object reference not set to an instance of an object
这是用户控件:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="IVT_FormClient.ascx.cs" Inherits="Evi.Sc.Web.Evi.IVT.Sublayouts.IVT_FormClient" %>
<asp:Panel ID="pnlContainer" runat="server">
<asp:TextBox ID="txtClientNumber" runat="server"></asp:TextBox>
</asp:Panel>
访问修饰符是(在用户控件中):
public string TxtFirstName
{
get { return txtFirstName.Text; }
set { txtFirstName.Text = value; }
}
在网络表单中,我有控件参考:
<%@ Reference Control="~/Evi/IVT/Sublayouts/IVT_FormClient.ascx" %>
在用户控件背后的代码是:
public partial class frm_VerifyIdentity : System.Web.UI.Page
{
IVT_FormClient ivtFormClient = new IVT_FormClient();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
IVT_FormClient ivtFormClient = (IVT_FormClient)LoadControl("~/Evi/IVT/Sublayouts/IVT_FormClient.ascx");
Client UserClient = new Client();
UserClient = Load_ClientVerification(Server.HtmlEncode(Request.QueryString["ID"]).Trim());
if (UserClient != null)
{
ivtFormClient.TxtFirstName = UserClient.FirstName;
plhFormClient.Controls.Add(ivtFormClient);
}
}
}
}
发生的错误是这行代码:
ivtFormClient.TxtFirstName = UserClient.FirstName;