Results 1 to 4 of 4

Thread: Dynamically Adding Control Based On values from popup window

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2004
    Posts
    3

    Dynamically Adding Control Based On values from popup window

    Hi -

    I did this in asp and am converting to asp.net

    On a form I have fields with values from 3 separate tables.

    For 1 table which is a array of counties I create a "dynamic" array of controls within a div tag

    The div tag contents can be changed via the innerHTML tag

    <div id="countrylist">
    <table>
    <tr>
    <td><input type="hidden" name="hdnCountryID" value="1">US</td>
    </tr>
    <tr>
    <td><input type="hidden" name="hdnCountryID" value="2">Mexico</td>
    </tr>

    </table>
    </div>

    For example there is a hidden field and then the country name is show within a td tag.

    The fields are first populated on the data load - however the user can add additional values to the array by opening a popup window and selecting country values from a list box. I then call a javascript function in which I rebuild the table with what is already there, adding a new row for the new value from the popup and set the div.innerHTML. You might want to think of this as a dynamic array of controls

    Is this possible in .Net?

    Thanks!

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    While there is a way to add dynamic controls mirroring how you did it in asp....

    Perhaps the easier way is to put these controls in a data-bound list control (repeater or datalist).

    The initial values become serialized to viewstate, or stored in session.

    The postback from the javascript div will pass the new values in stored into an array inside a hidden field in the form.

    The asp.net framework will check for changes on that value, and parse out the values and determine new ones. It can make changes to the stored viewstate of values, and rebind the datalist control.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2004
    Posts
    3
    So I need to have a hidden form on the .net page
    and then bind to the datalist from the hidden field.

    I also need a delete button for each row - will this work

    Thanks for your help I am new to this

  4. #4
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    To add controls dynamically, I suggest reading

    aspnet.4guysfromrolla.com/articles/081402-1.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width