Professional Web Applications Themes

how to conditionaly add a usercontrol? (ASCX) - ASP.NET Building Controls

Hi guys I have two user controls (ascx) I want to place them conditionaly in my aspx page. How to do that? For exmple, If Request["variable"] = "1" then DisplayASCXcontrol(1) Else DisplayASCXcontrol(2) End If So, according to the users choice when the page loads, it will contain one of the user controls. rgds KK...

  1. #1

    Default how to conditionaly add a usercontrol? (ASCX)

    Hi guys

    I have two user controls (ascx)
    I want to place them conditionaly
    in my aspx page. How to do that?

    For exmple,

    If Request["variable"] = "1" then
    DisplayASCXcontrol(1)
    Else
    DisplayASCXcontrol(2)
    End If

    So, according to the users choice
    when the page loads, it will
    contain one of the user controls.

    rgds
    KK



    KK Guest

  2. #2

    Default Re: how to conditionaly add a usercontrol? (ASCX)

    KK wrote:
    > Hi guys
    >
    > I have two user controls (ascx)
    > I want to place them conditionaly
    > in my aspx page. How to do that?
    >
    > For exmple,
    >
    > If Request["variable"] = "1" then
    > DisplayASCXcontrol(1)
    > Else
    > DisplayASCXcontrol(2)
    > End If
    >
    > So, according to the users choice
    > when the page loads, it will
    > contain one of the user controls.
    >
    > rgds
    > KK
    Use the LoadControl method:
    Page.LoadControl("control1.ascx")

    See:
    [url]http://www.brettb.com/DynamicUserControlsWithLoadControl.asp[/url]

    --

    Jos


    Jos Branders Guest

  3. #3

    Default Re: how to conditionaly add a usercontrol? (ASCX)

    On Sat, 27 Nov 2004 17:50:40 +0100, "Jos Branders"
    <jnospambrandersfastmail.fm> wrote:
    >KK wrote:
    >> Hi guys
    >>
    >> I have two user controls (ascx)
    >> I want to place them conditionaly
    >> in my aspx page. How to do that?
    >>
    >> For exmple,
    >>
    >> If Request["variable"] = "1" then
    >> DisplayASCXcontrol(1)
    >> Else
    >> DisplayASCXcontrol(2)
    >> End If
    >>
    >> So, according to the users choice
    >> when the page loads, it will
    >> contain one of the user controls.
    >>
    >> rgds
    >> KK
    >
    >Use the LoadControl method:
    >Page.LoadControl("control1.ascx")
    >
    >See:
    >[url]http://www.brettb.com/DynamicUserControlsWithLoadControl.asp[/url]
    Or.. place both Ascx's on the webpage, set visible to false and set
    the visible to true if neccesary:

    this.FindControl('control1.ascx').Visible = true;

    That way you have more control on layout etc., but you need to hide
    the other control all the same.

    Leon.
    Leon Friesema Guest

Similar Threads

  1. referencing and anchor from within a usercontrol (ascx)
    By gary in forum ASP.NET Building Controls
    Replies: 3
    Last Post: December 20th, 09:54 AM
  2. When base class is used for UserControl, VS designer fails to load ASCX file
    By Jiri Zidek in forum ASP.NET Building Controls
    Replies: 5
    Last Post: April 6th, 11:48 PM
  3. Event not firing in usercontrol inside usercontrol
    By vatech1993@yahoo.com in forum ASP.NET Building Controls
    Replies: 4
    Last Post: February 28th, 02:25 PM
  4. .ascx UserControl Properties are set after Page_Load only on PostBacks
    By Douglas J. Badin in forum ASP.NET Building Controls
    Replies: 3
    Last Post: October 14th, 01:50 PM
  5. Replies: 1
    Last Post: July 3rd, 03:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139