0

here is the requirement:

i have a lable a textbox, and two buttons(+ and - button) on my asp.net page.

so when i click on the plus button it should add the the whole collection of controls to the page(i.e. lable, textbox and two buttons). And when i click on minus button it should remove the collection.

This should go on.meaning whenever i click on any plus button the control collection should get added to the page. I am wondering what will be the best approach to do it.

Any suggestion?

3 Answers 3

1

You could use postbacks and add your controls server-side, you could even use ajax to make it more seamless.

If you are going to go this way, remember to re-create your dynamic controls on each postback

Sign up to request clarification or add additional context in comments.

Comments

0

If post-backs don't bother you, then just do what you mentioned on server side in response to button click event.
Have some container, add and remove components dynamically, attach your event handlers to events of newly created objects.

Comments

0

Wrap the controls you want to show/hide in a panel. Then in the click event handlers of the buttons set the Visible property of the panel to true or false as you need.

Beware that your + button will need to be outside the panel otherwise you'll never get them back again.

2 Comments

I cant keep the controls in the page. because i can add as many controls i want.
@Subrat - I answered this question before you updated it. So my answer is incorrect, please disregard it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.