Re: creating usercotrols from webcontrol

Tech-Archive recommends: Fix windows errors by optimizing your registry



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\listselection.ascx.cs:123
Project.Controls.NexumProductGroups.CreateChildControls() in
c:\inetpub\wwwroot\nexumportal2\controls\nexumproductgroups.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:elKQhwDYFHA.252@xxxxxxxxxxxxxxxxxxxxxxx
> 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);
>
> }
>
>
>
> }
>
> }
>
>


.



Relevant Pages

  • Re: creating usercotrols from webcontrol
    ... ListSelection ListSelection1=new ListSelection; ... So I am dynamically loading user control.But I don't think this is the ... Object reference not set to an instance of an ... I am trying to add a usercontrol to the control collection of a ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: help plz!! Replace bit value with Image and bind it to repeater
    ... its working properly when i use HTML image control. ... Using membership and replace with a graphic by the name of the userid ... Another option is the GridView data binding event, ... Object reference not set to an instance of an object. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How do I set an object Reference?
    ... >> Object reference not set to an instance of an object. ... >> My guess is that that means it cannot find the control on the form. ... >> e As DataListItemEventArgs) ... >> It's in the OnItemDataBound event, so I don't know why it cannot find ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Change ImageButton visible property in code dynamically
    ... > Call the FindControl method with the name of the control you want. ... >> Dim row As DataRow ... >> Dim myImage As Image ... >> Not suprisingly I am getting the error "Object reference not set to an ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Getting error referencing Hyperlink from code-behind
    ... I'd better not post anymore when I am brain-dead. ... I guess I just have to find out why the control is not being found now. ... Protected Sub Page_PreRender(ByVal sender As Object, ... Object reference not set to an instance of an object ...
    (microsoft.public.dotnet.framework.aspnet)