ASP.NET, adding controls on client side

O

Oleg Ogurok

Hi all,


Does anyone have example of adding controls on the client side (DHTML)
and then persisting them as ASP.NET server controls on the server side?


For example, a page has an <input> box for entering e-mail address and
a button <Add more addresses>.

Each time a user clicks the button, another textbox is created via
JavaScript:

var tb = document.createElement("input");
tb.type = "text";
container.appendChild(tb);


When the user submits the page to the server, the ASP.NET engine should
somehow recreate all newly added controls (e.g. populate this.Controls
collection in CreateChildControls()) and restore their values.

I haven't been able to figure out how to restore values into the
controls
Any help/samples appreciated.

-Oleg.
 
S

sam

All you are getting back on the server-side is the forms collection -
you are not getting the client side contorls. The form collection
*will* however contain updates if you add form elements dynamically in
JS so thats good news. You would have to sniff out those form elements
and build the controls on the server side dynamically with the
information in the form elements. You'll also probably have to turn
view state off for another complicated reason.

But I don't think you want to do this. No one does it this way.
Perhaps more info as to what the *requirements* are for your project
will help.

-sam
 
P

Peter Johnson

There is a way to achieve this without posting back to the server as
such,

you could look into Ajax.Net which will allow you to achieve this
functionality.

Another way to do this simply would be to implement a datagrid of items
and everytime the user clicks the button to add a new row and set it
into edit mode within the datagrid. however this would mean posting
back to the server.

As Sam said in his post it is not possible for us to advise you better
without a bit more of a clue into what your specific goal is.

Regards,

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top