473,322 Members | 1,314 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,322 software developers and data experts.

creating usercotrols from webcontrol

hi , I am trying to add a usercontrol to the control collection of a
webcontrol but I get "Object reference not set to an instance of an object."
errors.On the other hand , by changing the code creating Usercontrol to
create a Webcontrol (label ,textbox etc) I can use it successfully.I think
there is a problem with childcontrolscreating.Is there any ideas ?

Note that : ListSelection is my user control.

-ersin gençtürk

I am sending the source code below :

public class ProductGroups: System.Web.UI.WebControls.WebControl,
INamingContainer

{

private bool _EditMode;
public ProductGroups()

{

}

/// <summary>

/// Turns control into editing mode

/// </summary>

public bool EditMode

{

get

{

return(_EditMode);

}

set

{

_EditMode=value;

}

}
protected override void CreateChildControls()

{

base.CreateChildControls ();

this.EnsureChildControls();

if (EditMode)

{

ListSelection ListSelection1=new ListSelection();

ListSelection1.DataValueField="ProductGroupId";

ListSelection1.DataTextField="ProductGroupName";

ListSelection1.NotSelectedItemsDataSource=//Some datasource code.

ListSelection1.NotSelectedItemsDataBind();

Controls.Add(ListSelection1);
}

else

{

Controls.Add(ProductGroupList1);

}

}

}
Nov 19 '05 #1
2 1346
I am gettin these errors :

[NullReferenceException: Object reference not set to an instance of an
object.]
Project.Controls.ListSelection.set_DataValueField( String value) in
c:\inetpub\wwwroot\nexumportal2\controls\listselec tion.ascx.cs:123
Project.Controls.NexumProductGroups.CreateChildCon trols() in
c:\inetpub\wwwroot\nexumportal2\controls\nexumprod uctgroups.cs:57
System.Web.UI.Control.EnsureChildControls() +92
System.Web.UI.Control.PreRenderRecursiveInternal() +38
System.Web.UI.Control.PreRenderRecursiveInternal() +125
System.Web.UI.Control.PreRenderRecursiveInternal() +125
System.Web.UI.Page.ProcessRequestMain() +1499
I can set Controls.ListSelection.DataValue property when I use this control
from a webpage.
"Ersin Gençtürk" <ers[spam]@gencturk.org> wrote in message
news:el*************@TK2MSFTNGP12.phx.gbl...
hi , I am trying to add a usercontrol to the control collection of a
webcontrol but I get "Object reference not set to an instance of an object." errors.On the other hand , by changing the code creating Usercontrol to
create a Webcontrol (label ,textbox etc) I can use it successfully.I think
there is a problem with childcontrolscreating.Is there any ideas ?

Note that : ListSelection is my user control.

-ersin gençtürk

I am sending the source code below :

public class ProductGroups: System.Web.UI.WebControls.WebControl,
INamingContainer

{

private bool _EditMode;
public ProductGroups()

{

}

/// <summary>

/// Turns control into editing mode

/// </summary>

public bool EditMode

{

get

{

return(_EditMode);

}

set

{

_EditMode=value;

}

}
protected override void CreateChildControls()

{

base.CreateChildControls ();

this.EnsureChildControls();

if (EditMode)

{

ListSelection ListSelection1=new ListSelection();

ListSelection1.DataValueField="ProductGroupId";

ListSelection1.DataTextField="ProductGroupName";

ListSelection1.NotSelectedItemsDataSource=//Some datasource code.

ListSelection1.NotSelectedItemsDataBind();

Controls.Add(ListSelection1);
}

else

{

Controls.Add(ProductGroupList1);

}

}

}

Nov 19 '05 #2
ok.I have found a way :

I changed this line :

ListSelection ListSelection1=new ListSelection();

to:
ListSelection
ListSelection1=(ListSelection)this.Page.LoadContro l("~/controls/ListSelectio
n.ascx");

So I am dynamically loading user control.But I don't think this is the
common way to do this.No Ideas ?

"Ersin Gençtürk" <ers[spam]@gencturk.org> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl...
I am gettin these errors :

[NullReferenceException: Object reference not set to an instance of an
object.]
Project.Controls.ListSelection.set_DataValueField( String value) in
c:\inetpub\wwwroot\nexumportal2\controls\listselec tion.ascx.cs:123
Project.Controls.NexumProductGroups.CreateChildCon trols() in
c:\inetpub\wwwroot\nexumportal2\controls\nexumprod uctgroups.cs:57
System.Web.UI.Control.EnsureChildControls() +92
System.Web.UI.Control.PreRenderRecursiveInternal() +38
System.Web.UI.Control.PreRenderRecursiveInternal() +125
System.Web.UI.Control.PreRenderRecursiveInternal() +125
System.Web.UI.Page.ProcessRequestMain() +1499
I can set Controls.ListSelection.DataValue property when I use this control from a webpage.
"Ersin Gençtürk" <ers[spam]@gencturk.org> wrote in message
news:el*************@TK2MSFTNGP12.phx.gbl...
hi , I am trying to add a usercontrol to the control collection of a
webcontrol but I get "Object reference not set to an instance of an

object."
errors.On the other hand , by changing the code creating Usercontrol to
create a Webcontrol (label ,textbox etc) I can use it successfully.I think there is a problem with childcontrolscreating.Is there any ideas ?

Note that : ListSelection is my user control.

-ersin gençtürk

I am sending the source code below :

public class ProductGroups: System.Web.UI.WebControls.WebControl,
INamingContainer

{

private bool _EditMode;
public ProductGroups()

{

}

/// <summary>

/// Turns control into editing mode

/// </summary>

public bool EditMode

{

get

{

return(_EditMode);

}

set

{

_EditMode=value;

}

}
protected override void CreateChildControls()

{

base.CreateChildControls ();

this.EnsureChildControls();

if (EditMode)

{

ListSelection ListSelection1=new ListSelection();

ListSelection1.DataValueField="ProductGroupId";

ListSelection1.DataTextField="ProductGroupName";

ListSelection1.NotSelectedItemsDataSource=//Some datasource code.

ListSelection1.NotSelectedItemsDataBind();

Controls.Add(ListSelection1);
}

else

{

Controls.Add(ProductGroupList1);

}

}

}


Nov 19 '05 #3

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

Similar topics

1
by: Owatona | last post by:
Hi to all... I have 3 classes derived from webcontrol. I the first i have two dropdownlist, in the second i have some buttons, and the third its the webcontrol that are instanciate the two...
0
by: Matze | last post by:
I have a function that has an Argument of type System.Web.UI.WebControls.WebControl. I want to set the text-property of that control. Of course it doesnt work if I cast that control to...
3
by: Christer | last post by:
Hi all! I recently created a MessageBox webcontrol for asp.net. This can be used as is, but I also want to take ude of it in other webcontrols. Right now i creating a ValidationSummary control,...
3
by: Ken Varn | last post by:
I am just starting the process of creating ASP.NET server controls. I have created controls for .NET applications, but have just started with ASP.NET. I am a little confused about some areas that...
9
by: kw | last post by:
What is the proper way to get the element ID for a client script? For example, suppose in the WebControl: TextBox t=new TextBox; t.ID=this.ClientID+"X"; .... Then elsewhere we want to access...
0
by: ~~~ .NET Ed ~~~ | last post by:
I am having problems getting this webcontrol working properly. Everything else works fine except having items. So here is the low-down on the control: 1. The control class is declared as shown...
5
by: Praveen | last post by:
I have script files embedded as resources in my dll. During runtime, I would like to write it out into the app dir (or a app sub-dir) and send the appropriate virtual path to the client. This makes...
1
by: tolisss | last post by:
Hi i m trying to find a way to create a user control that will have a mix of server controls but i cannot find a way to get the html that these controls are going to render before my control is...
4
by: Christian Hofmann | last post by:
Hello, How is it possible to use a hyperlink webcontrol inside a label webcontrol? I am using resources for globalisation. Now I have a text like this: Please click here to open that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: 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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.