|
Propblem with dynamic user control -- ScottFX --
Background: I am trying to create a dynamic survey. The set up is a question with 6 possible answers (Rating 1-5 with 0 being N/A). I want to place a usercontrol on the page that houses the question and the radio options for that question. I'm getting this error, but why? Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 7: End Get Line 8: Set(ByVal value) Line 9: lblQuestion.Text = value <---Error here Line 10: End Set Line 11: End Property Default.aspx Source: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" debug = "true" %> <%@ Register Src="question.ascx" TagName="question" TagPrefix="uc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "><html xmlns=" http://www.w3.org/1999/xhtml " ><head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:PlaceHolder ID="questions" runat="server"></asp:PlaceHolder> </form> </body> </html> Default.aspx.vb Source: Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ucQuestion As New question ucQuestion.ID = "q1" ucQuestion.Question = "What is the question?" ucQuestion.answer = "0" questions.Controls.Add(ucQuestion) End Sub End Class question.ascx Source: <%@ Control Language="VB" AutoEventWireup="false" CodeFile="question.ascx.vb" Inherits="question" %> <table> <tr> <td style="width: 511px; height: 20px" align = "left" valign = "top"> <asp:Label ID="lblQuestion" runat="server" Text="Label" Width="507px"></asp:Label> </td> <td style="width: 496px; height: 20px;" align = "left" valign = "top"> <asp:RadioButtonList ID="roAnswer" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" ForeColor="White" Width="189px"> <asp:ListItem Value="1"></asp:ListItem> <asp:ListItem Value="2"></asp:ListItem> <asp:ListItem Value="3"></asp:ListItem> <asp:ListItem Value="4"></asp:ListItem> <asp:ListItem Value="5"></asp:ListItem> <asp:ListItem Value="0"></asp:ListItem> </asp:RadioButtonList></td> </tr> </table> question.ascx.vb Source Partial Class question Inherits System.Web.UI.UserControl Public Property Question() Get Return lblQuestion.Text End Get Set(ByVal value) lblQuestion.Text = value End Set End Property Public Property answer() Get Return roAnswer.Text End Get Set(ByVal value) roAnswer.Text = value End Set End Property End Class |