Hi everyone,
I'm having a problem with UserControls. Specifically, they don't show up and I'm getting null reference exceptions during load.
protected void Page_Load(object sender, EventArgs e) {
lblScore.Text = q.Score.ToString();
lnkQuote.Text = "#" + q.QuoteID;
lblTime.Text = q.Submitted.ToString( "yyyy-mm-dd" );
divBody.InnerText = q.Text;
divComm.InnerText = q.Comment;
}Each of the controls are null, and I don't know why. "q" is defined as it should be. The ASCX page is the following
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="QuoteControl.ascx.cs" Inherits="QuoteControl" %>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
Quote
<asp:LinkButton ID="lnkQuote" runat="server" onclick="lnkQuote_Click">a</asp:LinkButton>
Score: <asp:Label id="lblScore" runat="server">a</asp:Label> [
<asp:LinkButton ID="lnkUp" runat="server" Text="+" CommandArgument="up"
onclick="lnkUp_Click">a</asp:LinkButton> /
<asp:LinkButton ID="lnkDown" runat="server" Text="-" CommandArgument="down"
onclick="lnkDown_Click">a</asp:LinkButton> ]
- Submitted: <asp:Label ID="lblTime" runat="server">a</asp:Label>
<asp:Label ID="lblError" runat="server">a</asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<div id="divBody" runat="server">a</div>
<div id="divComm" runat="server">a</div>And the control is dynamically created with the following foreach ( Model.Quote q in quotes ) {
QuoteControl uc = new QuoteControl();
uc.QuoteInfo = q;
uc.Visible = true;
this.Controls.Add( uc );
}
Am I missing something? I'm using Web Dev 2008.
If you need any more info, just let me know. Thanks :)