473,326 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

null references in my user control!!

I've got a really annoying problem, and I feel like i've tried everything ....

I've got a really simple usercontrol, containing a single dropdown.

In the Page_Load of the usercontrol, i want to set the items of the drop
down, but the control reference in the code behind file is always undefined.

the id is correct and I've created lots of user control before and never had
this problem. what am i missing??

ascx
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="SelectorControl.ascx.cs" Inherits="MyNameSpace.SelectorControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:DropDownList id="DropDownList1" runat="server"
Width="256px"></asp:DropDownList>
namespace MyNameSpace
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for CurrencySelectorControl.
/// </summary>
public class CurrencySelectorControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;

private void Page_Load(object sender, System.EventArgs e)
{
// DropDownList1 == null
}

#region Web Form Designer generated code
}
}
please help?

--
TIA
Sam Martin
Apr 27 '06 #1
4 1967
OJ
Hi Sam,
does this work?

protected System.Web.UI.WebControls.DropDownList DropDownList1;

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack) DropDownList1 = this.yourdropdownlistname;
}
A better idea might be to derive your class from
System.Web.UI.WebControls.DropDownList

Hth,
O

Apr 27 '06 #2
I coudln't help but notice that your user control ascx file inherits from
MyNameSpace.SelectorControl

but your user control class is actually

MyNameSpace.CurrencySelectorControl

my guess is that this inconsistency is the root of your problem..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:A8**********************************@microsof t.com...
I've got a really annoying problem, and I feel like i've tried everything
....

I've got a really simple usercontrol, containing a single dropdown.

In the Page_Load of the usercontrol, i want to set the items of the drop
down, but the control reference in the code behind file is always
undefined.

the id is correct and I've created lots of user control before and never
had
this problem. what am i missing??

ascx
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="SelectorControl.ascx.cs"
Inherits="MyNameSpace.SelectorControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:DropDownList id="DropDownList1" runat="server"
Width="256px"></asp:DropDownList>
namespace MyNameSpace
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for CurrencySelectorControl.
/// </summary>
public class CurrencySelectorControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;

private void Page_Load(object sender, System.EventArgs e)
{
// DropDownList1 == null
}

#region Web Form Designer generated code
}
}
please help?

--
TIA
Sam Martin

Apr 27 '06 #3
yeah, sorry. changed for post purposes.

it is correct.

with regards to OJ's suggestion, "this.yourdropdownlistname" should be
this.DropDownList1, do you mean do FindControl()?

The problem is that the controls collection for the user control (this) is
empty. Calling EnsureChildControls doesn't help either.

In the final control there will be more controls than a single drop down, so
don't want to inherit from DropDownList

any other ideas ?
--
TIA
Sam Martin
"Karl Seguin [MVP]" wrote:
I coudln't help but notice that your user control ascx file inherits from
MyNameSpace.SelectorControl

but your user control class is actually

MyNameSpace.CurrencySelectorControl

my guess is that this inconsistency is the root of your problem..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:A8**********************************@microsof t.com...
I've got a really annoying problem, and I feel like i've tried everything
....

I've got a really simple usercontrol, containing a single dropdown.

In the Page_Load of the usercontrol, i want to set the items of the drop
down, but the control reference in the code behind file is always
undefined.

the id is correct and I've created lots of user control before and never
had
this problem. what am i missing??

ascx
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="SelectorControl.ascx.cs"
Inherits="MyNameSpace.SelectorControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:DropDownList id="DropDownList1" runat="server"
Width="256px"></asp:DropDownList>
namespace MyNameSpace
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for CurrencySelectorControl.
/// </summary>
public class CurrencySelectorControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;

private void Page_Load(object sender, System.EventArgs e)
{
// DropDownList1 == null
}

#region Web Form Designer generated code
}
}
please help?

--
TIA
Sam Martin


Apr 27 '06 #4
ok, sussed it.

thanks for that though. was a typo as it turned out. your suggestion made
me look twice at it.

cheers.

--
TIA
Sam Martin
"Karl Seguin [MVP]" wrote:
I coudln't help but notice that your user control ascx file inherits from
MyNameSpace.SelectorControl

but your user control class is actually

MyNameSpace.CurrencySelectorControl

my guess is that this inconsistency is the root of your problem..

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:A8**********************************@microsof t.com...
I've got a really annoying problem, and I feel like i've tried everything
....

I've got a really simple usercontrol, containing a single dropdown.

In the Page_Load of the usercontrol, i want to set the items of the drop
down, but the control reference in the code behind file is always
undefined.

the id is correct and I've created lots of user control before and never
had
this problem. what am i missing??

ascx
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="SelectorControl.ascx.cs"
Inherits="MyNameSpace.SelectorControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:DropDownList id="DropDownList1" runat="server"
Width="256px"></asp:DropDownList>
namespace MyNameSpace
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for CurrencySelectorControl.
/// </summary>
public class CurrencySelectorControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;

private void Page_Load(object sender, System.EventArgs e)
{
// DropDownList1 == null
}

#region Web Form Designer generated code
}
}
please help?

--
TIA
Sam Martin


Apr 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: WebBuilder451 | last post by:
I've created a simple function to capture the userid when a page is hit. I can include this function in the page load using if not ispostback, but i'd perfer to place it in the page load event of...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
5
by: Norsoft | last post by:
I have a .Net 1.1 application which is downloaded into an aspx page. It is a dll which inherits from System.Windows.Forms.UserControl. It works fine on a PC with only the 1.1 Framework. However,...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
5
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I...
4
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
0
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
2
by: Mark | last post by:
Hi. I am making a user control right now, and it looks something like this: <script runat="server"> public string SelectCommand { set { // see below for why the following line is here.
4
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.