Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic user controls

    Hello,

    I'm evaluating user controls (.ascx) to use them in a web I'm developing, and I have found that work different if they are static (placed in the .aspx at design time) or dynamic (loaded in a PlaceHolder or Panel in .aspx Page_Load()).

    For example: inside the .ascx control I use a DropdownList (with AutoPostback), and I want update other data displayed in the control depending on the selected value in the dropdownlist. If the .ascx is static, after a postback, the selected value is available in the Page_Load() event of the control. However, if the .ascx is dynamic, the selected value is available in the Page_PreRender() event (in Page_Load() is available the previous value).

    Is correct this behaviour? Is it possible to make the dynamic user controls work like static in terms of page events?
    I don't know if I'm doing something wrong (or forgetting something).

    Regards.

  • #2
    Regular Coder
    Join Date
    Dec 2007
    Posts
    137
    Thanks
    1
    Thanked 21 Times in 21 Posts
    I'm pretty sure in the past I've done what you are doing, using dropdownlist controls to trigger other dropdownlist controls, both as user controls. But I do remember had to use some workarounds as it wasn't as straightforward as one would think. Cascading dropdownlist are tricky in general.

    That was awhile ago, and if I were to do that now, I would use Ajax as it would be easier. You could code it yourself (make your own control using javascript/jquery) or even easier, use ASP.NET Ajax Control Toolkit. Here's the cascading dropdown control:
    http://www.asp.net/ajax/ajaxcontrolt...gDropDown.aspx

    I haven't tried it as a usercontrol, but I would imagine it would be easier since it's all one control, rather than having to chain several controls, like you are doing.

    There are also other controls, so you may find the one you want for your purpose as maybe you aren't cascading your dropdowns, but want to trigger something us, like a listbox, etc. Look at the sample list on that page of the right menu.

    Note I don't know which ASP.NET version you are using (2.0, 3.5, 4.0) so you'll have to download the appropriate Ajax Control Toolkit for your version, like version 1.x for ASP.NET 2.0, version 3.x for ASP.NET 3.5 (and yes they skipped version 2.x as the version numbering system confused people). I forget, but ASP.NET 4.0 might have it included by default (I don't have VS 2010 open right now so I can't check).

  • #3
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your response, but the problem is the load of dynamic user controls, not the update of cascading controls. I've solved my problem loading the user control in Page_Init().


  •  

    Posting Permissions

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