Hi,<BR><BR>I am building an aspx Admin page consisting essentially of a series of TextBoxes and DropDownLists. This Admin page will do two different things, depending on what it finds in the QueryString: either (a) input new data into an Access DB or (b) pull existing data out of the DB and display it, so it can be edited and updated. <BR><BR>When attempting to do (b) I am having problems setting the properties of a DropDownList which is part of a UserControl, and I'm hoping someone can help me find out why it isn't working.<BR><BR>The DDL in question is part of UserControl "PostedByDDL.ascx" (all code below). This simple UserControl consists of a DropDownList, the DB query to populate it, and a Public Property allowing the DDL's selected item to be both read and set from the page holding the UserControl. <BR><BR>This PostedByDDL.ascx UserControl is itself part of another UserControl, "AddMessageTemplate.ascx". The relevant part of this second UserControl is the "Public Sub DisplayExistingMessageDetails", in which I set the Public Property of the PostedByDDL UserControl:<BR> ucPostedByDDL.PostedBy = Number<BR><BR>The AddMessageTemplate.ascx UserControl is itself displayed in MainPage.aspx. In the Page_Load event of this aspx page, the "DisplayExistingMessageDetails" Subroutine is called. Theoretically, this should pass an integer (in this case, "3") to the AddMessageTemplate.ascx UserControl, which then uses this integer to set the PostedBy property of the PostedByDLL.ascx UserControl. Ultimately this integer should then select a particular item in the DDL which comprises the UI element of PostedByDLL.ascx.<BR><BR>Well, that's what's supposed to happen. What in fact happens is that I get the following error message:<BR><BR> Object reference not set to an instance of an object.<BR> at ASP.PostedByDDL.set_PostedBy(Int32 Value)<BR><BR><BR>I have no idea why an object is not being found here. The hierarchy of controls is clear; there is a DDL in the lowest UserControl, PostedByDDL.ascx. This UserControl is properly registered in the higher UserControl AddMessageTemplate.ascx. This higher UserControl is in turn properly registered in the holding MainPage.aspx.<BR><BR>So why on earth is this error message coming up????<BR><BR>I've spent ages trying to work this one out, and my one conclusion is that I don't know what's going on! I really hope someone out there has the patience to look at my code (I've tried to simplify it as much as possible without losing shape) and help me out here!<BR><BR>Thanks in advance,<BR><BR>JON<BR><BR><BR><BR>*****************<BR>PostedByDDL.ascx<BR>*****************<BR><BR><%@ Control Language="VB" ClassName="PostedByDDL"%><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.Oledb" %><BR><BR><script language="VB" runat="server"><BR><BR>Dim objDatabase as new BusinessObjects.Database<BR>Dim ds as new DataSet()<BR><BR><BR>Sub Page_Load(obj as object, e as eventargs)<BR><BR> objDatabase.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")<BR> objDatabase.DataSet = ds<BR> <BR> objDatabase.CreateDataTable("tblPostedBy", "SELECT * FROM tblPeople;")<BR> ddPostedBy.DataSource = ds.Tables("tblPostedBy")<BR> ddPostedBy.DataTextField = "People"<BR> ddPostedBy.DataValueField = "PersonID"<BR> <BR> If not Page.IsPostBack then<BR> ddPostedBy.DataBind()<BR> ddPostedBy.Items.FindByText("Porritt, Jonathan").Selected = true<BR> end if<BR><BR>end sub<BR><BR><BR><BR>Public Property PostedBy As Integer<BR> Get<BR> Return ddPostedBy.SelectedItem.Value <BR> End Get<BR> Set<BR> ddPostedBy.SelectedItem.Selected = false<BR> ddPostedBy.Items.FindByValue(value).Selected = true<BR> End Set<BR>End Property<BR> <BR></script><BR><BR><BR><asp
ropDownList runat="server" id="ddPostedBy" /><BR><BR><BR><BR><BR>************************<BR>AddMessageTemplate.ascx<BR>************************<BR><BR><BR><%@ Control Language="VB" ClassName="AddMessageTemplate" %><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.Oledb" %><BR><BR><%@ Register TagPrefix="PostedByDDL" TagName="UserControl" src=http://aspmessageboard.com/archive/index.php/"PostedByDDL.ascx" %><BR><BR><BR><script language="VB" runat="server"><BR><BR> Public Sub DisplayExistingMessageDetails(Number as Integer)<BR> ucPostedByDDL.PostedBy = Number<BR> '++++++++++++++++++++++++++<BR> ' ERROR IS CAUSED HERE <BR> '++++++++++++++++++++++++++<BR> End Sub<BR> <BR></script><BR><BR><BR><PostedByDDL:UserControl id="ucPostedByDDL" runat="server" /><BR><BR><BR><BR><BR><BR>**************<BR>MAINPAGE.aspx<BR>**************<BR><BR><BR><%@ Page Language="VB" %><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.Oledb" %><BR><BR><%@ Register TagPrefix="UserControl" TagName="Message" src="AddMessageTemplate.ascx" %><BR><BR><BR><script language="VB" runat="server"><BR> <BR>Sub Page_Load(sender as object, e as eventargs)<BR> ucMessage.DisplayExistingMessageDetails(3)<BR>End Sub<BR><BR><BR></script> <BR><BR><html><BR><form runat="server" name="form1" id="form1"><BR> <BR> <UserControl:Message id="ucMessage" runat="server" /><BR><BR></form> <BR></html><BR>Hi All,<BR><BR>In case anyone's interested, I solved the problem eventually. In MainPage.aspx, I simply replaced:<BR><BR>Sub Page_Load(sender as object, e as eventargs)<BR>ucMessage.DisplayExistingMessageDetails(3)<BR>End Sub<BR><BR>with:<BR><BR>Sub Page_PreRender(sender as object, e as eventargs)<BR>ucMessage.DisplayExistingMessageDetails(3)<BR>End Sub<BR><BR>and it worked! What a relief after about two days of debugging hell!<BR><BR><BR>JON<BR><BR>
