Assign value to customer control property

Savanah

New Member
Hi DotNet GURU,<BR>Anyone please help i'm trying to get this below sample code to run.<BR>Compiling is OK but when i run it got Error say<BR><BR>Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.<BR>Source Error: <BR>Line 26: MyControl.Format = WebUserControl1.FooterFormat.LongDate<BR>Line 27: ElseIf RadioButton2.Checked = True Then<BR>Line 28: MyControl.Format = WebUserControl1.FooterFormat.ShortTime<BR>Line 29: End If<BR>Line 30: End Sub<BR><BR>Thanks!!<BR><BR>Here are the my code behide page<BR><BR>********************<BR>WebUserControl1.ascx.vb<BR>********************<BR>Public MustInherit Class WebUserControl1<BR> Inherits System.Web.UI.UserControl<BR> Protected WithEvents Label1 As System.Web.UI.WebControls.Label<BR><BR> Public Enum FooterFormat<BR> LongDate<BR> ShortTime<BR> End Enum<BR><BR> Private _Format As FooterFormat = FooterFormat.LongDate<BR> Public Property Format() As FooterFormat<BR> Get<BR> Return _Format<BR> End Get<BR> Set(ByVal Value As FooterFormat)<BR> _Format = Value<BR> End Set<BR> End Property<BR><BR>#Region " Web Form Designer Generated Code "<BR>..........<BR>#End Region<BR><BR> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> 'Put user code to initialize the page here<BR> Label1.Text = "This page was saved at "<BR> If _Format = FooterFormat.LongDate Then<BR> Label1.Text &= DateTime.Now.ToLongDateString()<BR> ElseIf _Format = FooterFormat.ShortTime Then<BR> Label1.Text &= DateTime.Now.ToShortTimeString()<BR> End If<BR> End Sub<BR><BR>End Class<BR><BR>**************<BR>WebForm1.aspx.vb<BR>***************<BR>Public Class WebForm1<BR> Inherits System.Web.UI.Page<BR> Protected WithEvents Button1 As System.Web.UI.WebControls.Button<BR> Protected WithEvents RadioButton1 As System.Web.UI.WebControls.RadioButton<BR> Protected WithEvents RadioButton2 As System.Web.UI.WebControls.RadioButton<BR> Protected MyControl As WebUserControl1<BR><BR>#Region " Web Form Designer Generated Code "<BR>.....<BR>#End Region<BR><BR> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> If RadioButton1.Checked = True Then<BR> MyControl.Format = WebUserControl1.FooterFormat.LongDate<BR> ElseIf RadioButton2.Checked = True Then<BR> MyControl.Format = WebUserControl1.FooterFormat.ShortTime<BR> End If<BR> End Sub<BR><BR>End Class<BR>
 
Back
Top