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

  • Home
  • SEARCH
  • 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 8309765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:13:16+00:00 2026-06-08T19:13:16+00:00

I have a web user control ( OrderDefinition.ascx ) which has a dropdownlist (

  • 0

I have a web user control (OrderDefinition.ascx) which has a dropdownlist (ddl_CustomerCode), which is populated by web user control’s page_load function

    public void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            ddl_CustomerCode.DataSource = OrderDefinitionData.GetCustomers();
            ddl_CustomerCode.DataTextField = "CustomerCode";
            ddl_CustomerCode.DataValueField = "CustomerName";                
            ddl_CustomerCode.DataBind();
         }
    }

In my default.aspx page I dynmically add this web user control

    Control x = LoadControl("Controls/OrderDefinition.ascx");
    Panel1.Controls.Add(x);

I want to pass parameter to this web user control from my default.aspx, and I come up with the idea of using a session or viewstate or cache to use. So now my default.aspx looks like

    Session["myParam"] = "customerNo1";
    Control x = LoadControl("Controls/OrderDefinition.ascx");
    Panel1.Controls.Add(x);

And my Page_Load will look like

    public void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string myParam = Session["myParam"];
            ddl_CustomerCode.DataSource = OrderDefinitionData.GetCustomers(myParam);
            ddl_CustomerCode.DataTextField = "CustomerCode";
            ddl_CustomerCode.DataValueField = "CustomerName";                
            ddl_CustomerCode.DataBind();
         }
    }

The problem is I am not sure about the way I code above, Should I trust this architecture? Please clarify me if this is the correct way to pass a parameter to a web user control.

  • 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-06-08T19:13:18+00:00Added an answer on June 8, 2026 at 7:13 pm

    As other have suggested you can do this in your ascx:

        public string myParam { get; set; }
        public void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddl_CustomerCode.DataSource = OrderDefinitionData.GetCustomers(myParam);
                ddl_CustomerCode.DataTextField = "CustomerCode";
                ddl_CustomerCode.DataValueField = "CustomerName";                
                ddl_CustomerCode.DataBind();
             }
        }
    

    Then do this in your ASPX:

    WebControl1 x = (WebControl1)Page.LoadControl("Controls/OrderDefinition.ascx");
    x.myParam = "customerNo1";
    Panel1.Controls.Add(x);
    

    Note the casting to your TYPE of web control when you instantiate your web control through the LoadControl function – its important to do this cast so that your properties and methods are accessible to you.

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

Sidebar

Related Questions

I have created a web user control (MemberDetails.ascx) which is loaded dynamically on a
I have a base user control (inherited from System.Web.UI.UserControl ) public delegate void MyEventHandler(object
I have made a web user control (.ascx) which consists of the two html
I have a web user control with a dropdownlist inside of it. When the
my structure is like this: master page aspx(web form) ascx(user control) I have a
I used to have an embedded user control in an ASP.NET web site which
I have created a web user control called Activity. I have defined a public-facing
I have a web user control which call some methods of an interface. Four
I have a web user control (ascx) in my project and I would like
I have a web user control, that has a table with 3 columns 1)

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.