Roshan
Roshan

Reputation:

Dynamically created button

When I click a button I need to create some Textboxes dynamically. The values of the textboxes must be entered in the database by clicking a button which should be enerated dynamically below these textboxes. How do I acheive this?? I need to have a Click event for this newly generated button.

Upvotes: 1

Views: 205

Answers (2)

Al Katawazi
Al Katawazi

Reputation: 7242

Use ASP.NET MVC, if you want dynamic creation of elements on your page, MVC Framework is much better suited for this than Webforms are. Save yourself the headache.

Upvotes: 1

tvanfosson
tvanfosson

Reputation: 532465

You could simply handle the input of the new data in Page_Load on postback and have your newly created button just postback the form. You'll need to look through the form parameters for the new textboxes, obviously, and have a way to differentiate them from the previously existing ones.

If you must handle them with a button click event handler, you could try adding a hidden ("display: none;", not "visible=false") button to your page and associating a server-side click handler with it. Have the client-side click handler cause a click-event on the hidden button when it is clicked. This should invoke the server-side click handler for the hidden button. Again, you'll need to find the new textboxes in the request's form parameters since they won't exist as server-side controls.

Upvotes: 0

Related Questions