Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 948391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:14:18+00:00 2026-05-15T23:14:18+00:00

I have a Masterpage that has Treeview. You can select some nodes there. Based

  • 0

I have a Masterpage that has Treeview. You can select some nodes there.
Based on the selection you get some items in the Default.aspx’s Placeholder, you get a image and a linkbutton placed in a Panel. Like this :

alt text

This code is in the Default.aspx that has the Masterpage.

        TreeView nav_tree = ((TreeView)Master.FindControl("treeview_Navigation"));
        string selectedNode = nav_tree.SelectedNode.Value;

        var query = from n in dc.Nemanet_Navigations
                    where n.UserId == userGuid && n.Nav_pID.ToString() == selectedNode && n.Nav_IsFile == false
                    orderby n.Nav_Name
                    select n;
        foreach (var item in query)
        {

            Panel div = new Panel();
            div.ID = item.Nav_ID.ToString();
            div.CssClass = "BulletDiv";
            content_default.Controls.Add(div);

            Image picture = new Image();
            picture.ImageUrl = "~/Icons/New_Folder.png";
            div.Controls.Add(picture);

            div.Controls.Add(new LiteralControl("<br/>"));

            LinkButton description = new LinkButton();
            description.Text = item.Nav_Name;
            description.PostBackUrl = "default.aspx";
            div.Controls.Add(description);

        }

There seems to be problem when i create the controllers at runtime, when the site does a postback, lets say if i click “Enska” in the treeview i get the results in the image above. Lets say that i then click “The Punk Panther” i get a error.

An error has occurred because a
control with id ‘ctl00$CPH_Main$ctl05’
could not be located or a different
control is assigned to the same ID
after postback. If the ID is not
assigned, explicitly set the ID
property of controls that raise
postback events to avoid this error.

Also, how would i go by making a event handler for the linkbutton at runtime, can i make one event handler that every linkbutton uses or what ?
I want the folder and the linkbutton to be clickable and link to the same place, is it simpler to make the whole Panel clickable, if so, how would i get a “OnClick” event on it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:14:18+00:00Added an answer on May 15, 2026 at 11:14 pm

    Your problem is related to the sometimes difficult to comprehened ASP.NET Page Lifecycle.

    The control hierarchy you create at runtime is not recreated at the correct point in the page life cycle during a postback request, if at all.

    The “classic” approach that other web controls (e.g. DataGrid) take to tackle this problem is to serialise the data loaded into them into viewstate so that on postback, the control hierarchy can be reconstructed from postback values alone (without having to query the database again). However, implementing such an approach may not be appropriate in your circumstance.

    Instead, you could build an array (or other serialisable enumeration) of item key values (item.Nav_ID) that were used to build the previous control hierarchy, and add this to viewstate, e.g.:

    List<Int32> navIdValues = new List<Int32>();
    foreach (var item in query)
    {
        navIdValues.Add(item.Nav_ID);
    }
    Page.ViewState("NavIdValues") = navIdValues
    

    Then, during the Page.Init event of an incoming postback, retrieve the values you used to build the control hierarchy in the previous request:

    List<Int32> navIdValues = Page.ViewState("NavIdValues") as List<Int32>;
    

    Re-execute your query, building a dictionary of item’s accessible by their Nav_ID:

    IDictionary<Int32, ??itemtype??> items = query.ToDictionary(n => n.Nav_Id);
    

    And then re-build the control hierarchy as it existed in the previous request:

    foreach (Int32 navId in navIdValues)
    {
         var item = items(navId); 
    
         Panel div = new Panel();
         div.ID = item.Nav_ID.ToString();
         div.CssClass = "BulletDiv";
    
         ... etc ...
    }
    

    Then your postback event’s should fire as expected, because the control hierarchy has been recreated before postback event handling. This may not be the most optimal solution, but is a workable one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MasterPage that has two image buttons , and two content pages,
I have defined CSS in MasterPage so that all pages can use the same
I have a web application where the masterPage/template contains some static HTML that never
So I have a masterpage that has an image whos source is a controller
I have a usercontrol that has some checkboxes in it. On postback i want
I have a MasterPage that has ViewData passed to it. I would really like
I have a website that has some intense graphics, and people with slow connections
I have a Masterpage like that : ... <head id=Head1 runat=server> <asp:ContentPlaceHolder ID=HeadContent runat=server
I have a literal control in a masterpage that I would like to find
Currently I have a site that is set up using a masterpage and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.