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 6705611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:25:26+00:00 2026-05-26T07:25:26+00:00

This question is for an ASP.NET guru. Its driving me nuts. I have inherited

  • 0

This question is for an ASP.NET guru. Its driving me nuts.

I have inherited an ASP.NET Web Forms application. This application uses a complex
structure of nested user controls. While complex, it does seem necessary in this case.
Regardless, I have a page that uses a single UserControl. We will call this UserControl
root control. This UserControl is defined as follows:

widget.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="widget.ascx.cs" Inherits="resources_userControls_widget" %>
<div>
  <asp:Panel ID="bodyPanel" runat="server" />
</div>

widget.ascx.cs

public partial class resources_userControls_widget : System.Web.UI.UserControl
{
    private string source = string.Empty;
    public string Source
    {
        get { return source; }
        set { source = value; }
    }

    private string parameter1 = string.Empty;
    public string Parameter1
    {
        get { return parameter1; }
        set { parameter1 = value; }
    }

    private DataTable records = new DataTable();
    public DataTable Records
    {
        get { return records; }
        set { records = value; }
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        UserControl userControl = LoadControl(source) as UserControl;
        if (parameter1.Length > 0)
            userControl.Attributes.Add("parameter1", parameter1);
        bodyPanel.Controls.Add(userControl);
    }

    private void InsertUserControl(string filename)
    {
    }
}

In my application, I am using widget.ascx in the following way:
page.aspx

<uc:Widget ID="myWidget" runat="server"  Source="/userControls/widgets/info.ascx" />

page.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
  DataTable table = GetData();
  myWidget.Records = table;
}

Please notice how info.ascx is set as the UserControl we want to load in this case. This approach is necessary in this case. I’ve removed the extraneous code that justifies it to focus on the problem. Regardless, in info.ascx.cs I have the following:

info.ascx.cs

protected void Page_Load(object sender, EventArgs e)
{
  // Here's the problem
  // this.Parent.Parent is a widget.ascx instance.
  // However, I cannot access the Widget class. I want to be able to do this
  // Widget widget = (Widget)(this.Parent.Parent);
  // DataTable table = widget.Records;
}

I really need to get the value of the “Records” property from the Parent user control. Unfortunately, I can’t seem to access the Widget class from my code-behind. Are there some rules about UserControl visibility at compile time that I’m not aware of? How do I access the Widget class from the code-behind of info.ascx.cs?

Thank you!

  • 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-26T07:25:27+00:00Added an answer on May 26, 2026 at 7:25 am

    Firstly you need to create an interface and implement it to the Widget user control class.

    For instance,

    public interface IRecord
    {
        DataTable Records {get;set;}
    } 
    
    public partial class resources_userControls_widget : System.Web.UI.UserControl, IRecord
    {
     ...
    }
    

    And in code behind of Info.ascx.cs,

    protected void Page_Load(object sender, EventArgs e)
    {
      // Here's the problem
      // this.Parent.Parent is a widget.ascx instance.
      // However, I cannot access the Widget class. I want to be able to do this
      // Widget widget = (Widget)(this.Parent.Parent);
      // DataTable table = widget.Records;
    
      IRecord record=this.Parent.Parent;
      DataTable table = widget.Records;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me qualify this question. I'm working on a classic ASP.NET application (Web Forms)
This is odd, but we have written an asp.Net web application (all's well there)
For this question, I'm using ASP.NET Web Forms in C#, a web service and
ASP.Net MVC3 is cool and all but I have this question more out of
This is a beginner level question for asp.net MVC I have the following code
( Disclaimer: This question is not specific to ASP.NET) I have a control which
I have an ASP.NET website, but this question isn't really about technology, it is
I have a VERY similar question to this question: ASP.NET MVC C# dynamic radiobuttons
I'm expanding further on this question . I currently have an asp.net hyperlink for
I have an extension to this question: Vb6 "Tag" property equivalent in ASP.Net? The

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.