Tapas Bose
Tapas Bose

Reputation: 29806

ASP.NET Page Fragment

In my requirement I need to add or remove a sub-page or page-fragment (or similar component, I don't know the name, similar to User Control) dynamically.

The page-fragment can contains other controls like menu or button or textbox.

I have a dropdown menu. Depending on the selection of that menu I will add a fragment with textbox or a fragment with dropdown menu. There will be an option to remove any added fragment.

But I don't know what asp.net component will be handful to achieve this!

Any information will be very helpful. I am not using MVC.


Edit:

Well, this is similar to the Wicket Fragment. I didn't find any online demo, but found this blog, this might be useful to clarify my requirement.

Upvotes: 0

Views: 1169

Answers (1)

Beenish Khan
Beenish Khan

Reputation: 1583

A little more information will help. But assuming a little bit, I think you can do any of the following,

  1. Add controls using JQuery, handle the dropdown index change event and add code to display the textbox/dropdown.

  2. You can make a usercontrol with textbox/dropdown and add it to page controls whenever the dropdown changes.

  3. You can use a composite control and show/hide it accordingly. Composite controls are a little more complicated to write but can be distributed across projects while user controls can be used only in given projects.

For 2/3, put the new user control in a partial update control, handle dropdown's selected index change event at server side and update it's visibility according to your requirements.

First approach is recommended since it's done at client side and gives better user experience but it does need a little efforts.

Thanks!

Upvotes: 1

Related Questions