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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:23:50+00:00 2026-05-23T20:23:50+00:00

I have an issue currently that I can’t resolve. I have a user control

  • 0

I have an issue currently that I can’t resolve. I have a user control called “Dashboard” which then has the following markup, containing several subcontrols.

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Dashboard.ascx.cs" Inherits="BlueSEQ.Controls.Dashboard.Dashboard" %>
<%@ Register src="Administrator.ascx" tagname="Administrator" tagprefix="uc1" %>
<%@ Register src="Provider.ascx" tagname="Provider" tagprefix="uc2" %>
<%@ Register src="User.ascx" tagname="User" tagprefix="uc3" %>

<% if (isAdministrator)
{ %>
<uc1:Administrator ID="Administrator1" runat="server" />
<% }
else if (isProvider)
{  %>
<uc2:Provider ID="Provider1" runat="server" />
<% }
else
{  %>
<uc3:User ID="User1" runat="server" />
<% } %>

As you can see, I want it to display some controls or other controls depending on some conditions. However, all of these controls’ “Load” event get triggered, even if they are not used.

How can I prevent this?

  • 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-23T20:23:51+00:00Added an answer on May 23, 2026 at 8:23 pm

    If you can help it, try to avoid having conditional logic in your markup. It could make the views somewhat more difficult to understand for designers (if you’re working with designers) and more difficult to find and refactor this code in the future.

    You should also take a look at ASP.NET MVC: Avoiding Tag Soup. Although it’s ASP.NET MVC, it’s still a good example of how adding logic to your views can quickly make them very difficult and unpleasant to maintain (initial example).


    You could use the technique described here: How to: Add Controls to an ASP.NET Web Page Programmatically.

    Your markup would look something like this.

    <asp:PlaceHolder id="MyPlaceholder" />
    

    and your codebehind would have something along the lines of

    private void InitSection()
    {
        Control c;
    
        if( isAdministrator )
            c = Page.LoadControl("~\Administrator.ascx")
        else if( isProvider )
            c = Page.LoadControl("~\Provider.ascx") 
        else
            c = Page.LoadControl("~\User.ascx");
    
        MyPlaceholder.Controlls.Add(c);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database issue that i currently cannot wrap my head around with
We currently have an existing issue tracker, which the service management team utilise for
I have a user that is currently running my Winforms app on Win7. My
I have an issue that I can't solve by myself. The best thing would
I have a requirement to implement a web-service that can issue files to the
Currently we have a sequential workflow in sharepoint 2010 that has a delay activity.
I currently have an issue in my DLR language implementation where subsequent calls to
I currently have a issue with firefox, where all other browser behave in the
I do not currently have this issue , but you never know, and thought
I'm having an issue with multiple markers on google maps - I currently have

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.