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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically create controls

Status
Not open for further replies.

acent

Technical User
Feb 17, 2006
247
US
Hello.

I'm kind of lost here as to how to accomplish this, so I need some advice.

I want to build a query to the database dynamically. Specifically, allow, a user to select fields and their values to query the database and eventually return the result to the user as a CSV file. Sounds simple enough.

My first attempt was to create some controls and then use javascript to duplicate the controls. All was good except the page never returned the duplicated controls to the webserver. I guess this is built into .NET for reasons unbeknownst to me.

I'm thinking that instead of having a one page deal, I need a two page wizard - the first page to select the number of fields to query and the second to display the controls to perform the query. Although this sounds to me like I'm over-complicating the obvious.

I'm using VB.NET 2.0.

Thanks in advance.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Why do you need javascript and why do you need to duplicate controls? I am confused on what you are trying to do.
 
I want to build a query to the database dynamically. Specifically, allow, a user to select fields and their values to query the database and eventually return the result to the user as a CSV file. Sounds simple enough.
this is actually the most complex type of query to design because everything is driven by runtime variables, not design time constraints.

whether you compose the query using 1 webform or dozen, doesn't matter. all the webforms should be doing is collecting user input. the business logic of composing the query, executing the query and generating a csv should have nothing to with the web. the web is simply the pipeline for the user interface.

there are plenty of articles on the web about dynamic controls in webforms and how to handle them using the Page model (webforms).

if you think in terms of request/response and html, rather than webforms page life cycle the problem becomes "easier" to solve. it's still a complex problem.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
jbenson001 let me see if I can clarify

I have a drop down list:
Code:
<asp:DropDownList ID="ddlLimitBy" style="display:none;" runat="server" />
[code]

Which allows the user to select, say "client number". At which point javascript duplicates a list box control a with the clients listed. 

The user can then click a button to add another field, which uses the javascript to duplicate the ddlLimitBy and repeat the process.

Once the form is submitted, the VB needs to loop the ddlLimitBy dropdown boxes other controls with the user's selections and build the query. The interface works, now I just need to get the VB to work.

I have tried to loop the Request.Form collection, but it only loops the server-side controls and not the controls created by the javascript. I also tried to separate the  server side controls to a server side form, and then have a client side form (basic html form) for the created controls, but that only seemed to loop the submit button and not the client side controls.

I'm not sure how to get this going, but thanks for helping me.

"If it's stupid but works, it isn't stupid."
  -Murphy's Military Laws
 
make sure you assign an id and a name to the dynamically created input fields. here is an example:
Code:
<input type="hidden" id="foo" name="foo" value="1" />
I believe the Form collection works off of name, not id.

another test, pull the value from Request.Params collection. this is a an aggregation of most of the asp.net containers (session, items, form, query string, cookies).

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top