Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Controls - Client Side??

Status
Not open for further replies.

jrapp

Programmer
May 15, 2003
25
0
0
US
Hey everybody. I'm looking for a solution to a design problem/idea that I've run into. I need a method to create controls dynamically, client side, and have said controls be posted back to the server. I know how to make new controls in javascript, but I can't post them back into .net. Here's an example of what I'm trying to do: user open page, types info, clicks button, clicking add new line item where they can control the quantity, etc. Any good ideas? Thanks!!
 
if you're looking to dynamically create controls on the client end of things, you should investigate some possibilites using CSS. perhaps if you already know what controls will appear based on a user action, you could simply toggle a visible property (on a <div> or <span>) - provided that you have some kind of layout. it's also possible to create these elements as server controls (that are hidden) and pass client script to toggle this property.

bear in mind that the reason the asp.net processor knows what's going on in a post is because of the hidden VIEWSTATE field on a page. controls defined, declared, and initialized by the client will NOT be included in the property value. it's possible to generate XML date based on non-server control content that can be passed back to the server; this is a different subject altogether. you can forget about trying to alter the VIEWSTATE field on your own, unless your comfortable figuring out stuff like:
õò1‡5½ß3ÇÈÈab³y™=ßE&Z;À¾è]¼. i know i'm not. :)

there is a way to add controls dynamically server side if you don't mind the user going through a post/postback cycle. the common way to do this is to handle control building in the Page_Load event handler, where your dynamic elements are added to controls collection on the page, based on some set of conditionals. it's best if you set up the page's default construction with a placeholder type (or other protected server controls that provide a collection) that can be referenced in the event handler.

in the example you give above, a condition could be checked for a NULL or empty string. string contents would determine whether or not a contol would be added to the page's collection.

hope this helps.

..:: mirirom ::..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top