Print Page | Close Window

Select a usercontrol based on a variable

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=12103
Printed Date: 28 March 2026 at 11:06pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Select a usercontrol based on a variable
Posted By: Diep-Vriezer
Subject: Select a usercontrol based on a variable
Date Posted: 09 October 2004 at 8:11pm

Hi! I need to retrieve a variable from the querystring and based on that variable, show or not show some user controls. So I've already come this far:

<% switch(Request.Querystring("mid")
      {
             case "0":
                           break;
             case "1":
                           break;
             case "2":
                           break;
             default:
                           break;
        }
%>

Which ofcourse, doesn't do a thing. Even though this is C#, you should get the idea. Now, how can I create a different UserControl for each case?<% switch Request.Querystring("mid") { case 0: break; case 1: break; case 2: break; default: break; } %><% switch Request.Querystring("mid") { case 0: break; case 1: break; case 2: break; default: break; } %><% switch Request.Querystring("mid") { case 0: break; case 1: break; case 2: break; default: break; } %><% switch Request.Querystring("mid") { case 0: break; case 1: break; case 2: break; default: break; } %><% switch Request.Querystring("mid") { case 0: break; case 1: break; case 2: break; default: break; } %>



-------------
Gone..



Replies:
Posted By: michael
Date Posted: 10 October 2004 at 1:32am
Put a placeholder onto you page and then do

Dim myControl as Control
Case 0
myControl = me.LoadControl("control0.ascx")
Placeholder1.Controls.Add(myControl)
Case 1
....

Should give you an idea

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Mart
Date Posted: 10 October 2004 at 3:28am
I think he wants to dynamically hide controls not load them, in which case use:


<% switch(Request.Querystring("mid")
      {
             case "0":
             userControl1.Visibile = true;
         &nbs p;            &nbs p;    break;
             case "1":
            
userControl2.Visibile = true;
         &nbs p;            &nbs p;    break;
             case "2":
            
userControl3.Visibile = true;
         &nbs p;            &nbs p;    break;
             default:
             defaulUserControl.Visible = true;
         &nbs p;            &nbs p;    break;
        }
%>


And just set the visibility of all the controls to false in the designer


Posted By: Diep-Vriezer
Date Posted: 10 October 2004 at 7:02am

No I actually want to load different controls. Anyways, thanks guys!



-------------
Gone..



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net