ASP.NET, adding controls on client side

Discussion in 'ASP .Net' started by Oleg Ogurok, Apr 21, 2006.

  1. Oleg Ogurok

    Oleg Ogurok Guest

    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.
     
    Oleg Ogurok, Apr 21, 2006
    #1
    1. Advertising

  2. Oleg Ogurok

    sam Guest

    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
     
    sam, Apr 21, 2006
    #2
    1. Advertising

  3. 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
     
    Peter Johnson, Apr 22, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    14
    Views:
    4,220
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  2. Lau Lei Cheong
    Replies:
    1
    Views:
    636
    Lau Lei Cheong
    Oct 13, 2004
  3. =?Utf-8?B?U2lsZWVzaA==?=
    Replies:
    0
    Views:
    490
    =?Utf-8?B?U2lsZWVzaA==?=
    Nov 3, 2004
  4. Boss302
    Replies:
    0
    Views:
    1,109
    Boss302
    Nov 21, 2006
  5. Zoe Hart
    Replies:
    1
    Views:
    405
    Scott Wisniewski
    Jan 8, 2004
Loading...

Share This Page