Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • harald 7 posts 27 karma points
    Dec 16, 2011 @ 10:16
    harald
    0

    object not found in a parent usercontrol

    hi,

    i have a problem and found not the solution.
    In a usercontrol is a further usercontrol integrated.In the parent-usercontrol is a object.
    When i access in the child-usercontrol of the object in the parent-usercontrol, i become a error-message.
    Here is the code as example.

    Listing.ascx.cs

    public partial class Listing : System.Web.UI.UserControl
    {
    ....
    private ListingResult _listingResult;
    public SearchResult searchResult { get { return _searchResult; } }
    ....
    public Listing()
    {
    _searchResult = new SearchResult();
    }
    ....

    _searchResult = _searchResult.getSearchResultsFromQiuckSearch(Request["quickSearchString"]);
    ....
    if (_searchResult != null)
    {
    //a control display on the website for me
    Debugger.ausgabe += "Listing Zeile:79<br>searchResult.categorys.Count: " + searchResult.categorys.Count + "<br>";
    //intergrate the child-control
    _listingResult = (ListingResult)LoadControl("ListingResult.ascx");
    plh_listingMainContent.Controls.Add(_listingResult);
    }
    ....
    //integrated the control display
    this.lbl_1.Text = "<hr>anfang<hr>" + Debugger.ausgabe + "<hr>ende<hr>";
    }

    private ListingResult.ascx.cs

    public partial class ListingResult : System.Web.UI.UserControl
    {
    private Listing _parent;
    private SearchResult _searchResult;
    ...
    public ListingResult ()
    {
    _parent = new Listing();
    //to integrate the parent-usercontrol Listing
    _parent = (Listing)this.Parent;
    //my control display
    Debugger.ausgabe += "ListingResult Konstrutor<br>Listing.searchResult.categorys.Count: " + _parent.searchResult.categorys.Count + "<br>";

    }
    }

    I create the usercontrols in visual studio 10 on a local machine, to compile the code and copy the .ddl in the bin directory from umbraco on a webserver.
    When i only activate the control-display (Debugger.ausgabe) in Listing, code to compile, is okay, copy to the webserver and refresh the website, i see the
    display the category-list in searchResult have 5 entrys.

    When i activate the control-display (Debugger.ausgabe) in Listing and in ListingResult, code to compile, is okay, copy to the webserver, i become a error
    NullReferenceException: Object reference not set to an instance of an object.

    I not understand, the object is in the parent-usercontrol exist.

    Can you help me?

    Sorry, my english is not the best, i hope the problem is understandable.

    cu
    harald




  • harald 7 posts 27 karma points
    Dec 16, 2011 @ 13:36
    harald
    0

    I have a other solution found.

    Listing.ascx.cs

    ...... 

    _listingResult = (ListingResult)LoadControl("ListingResult.ascx");
    /* 16.12.2011 HKN
    * Erstellung der Ergbnisanzeige im Kindcontrol (ListingResult) durch diesen Funktionsaufruf
    * erst danach an dieses Control anfügen
     */

    //started the function in the child-control
    _listingResult.createResultList(_searchResult);
    plh_listingMainContent.Controls.Add(_listingResult);  

    ....

    cu

    harald 

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies