Process webform with many fields
-
Hello folks, I am fairly new to .Net and am having trouble figuring out the best way to process a Search WebFrom in my application. I have a form with 10 Fields, some are dropdown, Checkbox, and radio buttons, none are text boxes. Based on the user selection I want to be able to generate an SQL statement that will search the database and show the results in a DataList. The SQL statement will be fairly complex, with atleast 3 joins. What is the best method of processing this sort of form? I have experience in ASP, I processed such forms by making them submit to an ASP file which did the processing and redirect to the results page. With this many fields in the Form I am hesitant to use QueryString because I will have to created the QueryString on source page and then gather the data into variables again on the processing page. I would appreciate any ideas, I have exhausted all resources on sites such as this .. Thanks Mike
-
Hello folks, I am fairly new to .Net and am having trouble figuring out the best way to process a Search WebFrom in my application. I have a form with 10 Fields, some are dropdown, Checkbox, and radio buttons, none are text boxes. Based on the user selection I want to be able to generate an SQL statement that will search the database and show the results in a DataList. The SQL statement will be fairly complex, with atleast 3 joins. What is the best method of processing this sort of form? I have experience in ASP, I processed such forms by making them submit to an ASP file which did the processing and redirect to the results page. With this many fields in the Form I am hesitant to use QueryString because I will have to created the QueryString on source page and then gather the data into variables again on the processing page. I would appreciate any ideas, I have exhausted all resources on sites such as this .. Thanks Mike
Hi Mike. The approach I would recommend is to code for the
Click
event of your submit button and construct a query using aCommand
-type object, likeSqlCommand
(if your database is SQL Server) orOleDbCommand
. AddParameter
objects to your command to supply the values submitted from the user. Then use aDataAdapter
object's.Fill()
method to fill aDataSet
(i.e. execute the query and retrieve the results), set yourDataList
'sDataSource
method to theDataSet
, and execute theDataList
'sDataBind()
method. Ugh! That is a lot of steps! But it's really not that bad. Let me know if this is enough for you to go on, or if you'd like a fuller example. -
Hello folks, I am fairly new to .Net and am having trouble figuring out the best way to process a Search WebFrom in my application. I have a form with 10 Fields, some are dropdown, Checkbox, and radio buttons, none are text boxes. Based on the user selection I want to be able to generate an SQL statement that will search the database and show the results in a DataList. The SQL statement will be fairly complex, with atleast 3 joins. What is the best method of processing this sort of form? I have experience in ASP, I processed such forms by making them submit to an ASP file which did the processing and redirect to the results page. With this many fields in the Form I am hesitant to use QueryString because I will have to created the QueryString on source page and then gather the data into variables again on the processing page. I would appreciate any ideas, I have exhausted all resources on sites such as this .. Thanks Mike
Hi mike what i feel, ur basic problem is to fetch the values of all controls avail on ur page, then redirecting set of those values to another form or to use'em 2 build query. Check me if i m wrong. I wrote a short code which i hope can help u after some customization, n yeah, since i m also beginner so may b its not d best way to do even that thing which i wanna do -
private void Button1_Click(object sender, System.EventArgs e) { HtmlForm fr = (HtmlForm)this.FindControl("Form1"); for(int i=0; i UTSAV
-
Hi Mike. The approach I would recommend is to code for the
Click
event of your submit button and construct a query using aCommand
-type object, likeSqlCommand
(if your database is SQL Server) orOleDbCommand
. AddParameter
objects to your command to supply the values submitted from the user. Then use aDataAdapter
object's.Fill()
method to fill aDataSet
(i.e. execute the query and retrieve the results), set yourDataList
'sDataSource
method to theDataSet
, and execute theDataList
'sDataBind()
method. Ugh! That is a lot of steps! But it's really not that bad. Let me know if this is enough for you to go on, or if you'd like a fuller example.Dear Mike Ellison Thank you for your response. These steps you mention I have accomplished. But since I want to display the results on a Different page, using a Datalist with paging, which I am using PagedDataSource, your solution would not work. Basically I want to keep the form (search.aspx) on one page and show the results on (searchresults.aspx) a different page. I am thinking I can create my SQL select statement on Button_Click event on Search.aspx and execute the SQL on Searchresults.aspx on Page_Load. But how do I pass the SQL statement to the Searchresults.aspx page. How is it generally done? Thanks Mike
-
Hi mike what i feel, ur basic problem is to fetch the values of all controls avail on ur page, then redirecting set of those values to another form or to use'em 2 build query. Check me if i m wrong. I wrote a short code which i hope can help u after some customization, n yeah, since i m also beginner so may b its not d best way to do even that thing which i wanna do -
private void Button1_Click(object sender, System.EventArgs e) { HtmlForm fr = (HtmlForm)this.FindControl("Form1"); for(int i=0; i UTSAV
Dear utsav_verma, You are absolutely right on what I want to do. Basically I want to keep the form (search.aspx) on one page and show the results on (searchresults.aspx) a different page. I am thinking I can create my SQL select statement on Button_Click event on Search.aspx and execute the SQL on Searchresults.aspx on Page_Load. But how do I pass the SQL statement to the Searchresults.aspx page. How is it generally done? Thanks Mike
-
Dear Mike Ellison Thank you for your response. These steps you mention I have accomplished. But since I want to display the results on a Different page, using a Datalist with paging, which I am using PagedDataSource, your solution would not work. Basically I want to keep the form (search.aspx) on one page and show the results on (searchresults.aspx) a different page. I am thinking I can create my SQL select statement on Button_Click event on Search.aspx and execute the SQL on Searchresults.aspx on Page_Load. But how do I pass the SQL statement to the Searchresults.aspx page. How is it generally done? Thanks Mike
Hi Mike. Let me press you on this :) Although what you are describing (search form on one page, search results on another) is possible - and there's nothing wrong with doing it that way - it really isn't the ASP.NET way. Imagine this on your page: two
<asp:Panel>
controls - one holding the search form and one holding the DataList for the results. Initially, the results panel is hidden. When the user submits the search form, yourClick
event handler for the submit button hides the form panel, displays the results panel, constructs and executes the query, and sets theDataSource
property for theDataList
control. Specific to the database code, you could get even more sophisticated and seperate out your database code to its own class or assembly - effectively making a data tier for your application. In which case, all yourClick
code has to do is set the visibility of the two panels, and call the data tier function that retrieves the appropriate data from the database. There are other benefits to building a data tier, but save that for another post. My main point is that this (the search & results display) can all happen on one .aspx page, which I think you will find actually makes it easier to maintain. Plus, because of the built-inViewState
for controls, there are additional benefits. You could include a "Search Again" button in your results panel for example, then code itsClick
event very simply to hide the results panel and display the search form panel. Because ofViewState
, your search form is automatically filled in with the user's previous search values, which can be a very helpful thing for the user. In the world of classic ASP, that's a tricky thing to develop, but in ASP.NET it amounts to two lines of code (hide results panel, display form panel). Just some food for thought. :cool: -
Dear utsav_verma, You are absolutely right on what I want to do. Basically I want to keep the form (search.aspx) on one page and show the results on (searchresults.aspx) a different page. I am thinking I can create my SQL select statement on Button_Click event on Search.aspx and execute the SQL on Searchresults.aspx on Page_Load. But how do I pass the SQL statement to the Searchresults.aspx page. How is it generally done? Thanks Mike
Hi mike Since i m also not having a great experiance in .NET so i cant help u pin pointedly, but the code snap i gave in previous reply shld tell u d way to access the content of ALL controls, n by applying ur own logic u can make query, query string or whatever u want. Though using viewstate intelligently can reduce ur work. as u said,But how do I pass the SQL statement to the Searchresults.aspx page its better to pass the contents than build ur dynamic query on the target page n 4 that, i think, the best way is - 1 - access values of all controls 2 - put them in some hashtable kinda object 3 - put object in session, access session in next page Viewstate cant b helpful in this context since its limited to the page itself (as far as my knowledge is concerned, i dont wanna challenge biggies ;) ) Hope it help UTSAV
-
Hi Mike. Let me press you on this :) Although what you are describing (search form on one page, search results on another) is possible - and there's nothing wrong with doing it that way - it really isn't the ASP.NET way. Imagine this on your page: two
<asp:Panel>
controls - one holding the search form and one holding the DataList for the results. Initially, the results panel is hidden. When the user submits the search form, yourClick
event handler for the submit button hides the form panel, displays the results panel, constructs and executes the query, and sets theDataSource
property for theDataList
control. Specific to the database code, you could get even more sophisticated and seperate out your database code to its own class or assembly - effectively making a data tier for your application. In which case, all yourClick
code has to do is set the visibility of the two panels, and call the data tier function that retrieves the appropriate data from the database. There are other benefits to building a data tier, but save that for another post. My main point is that this (the search & results display) can all happen on one .aspx page, which I think you will find actually makes it easier to maintain. Plus, because of the built-inViewState
for controls, there are additional benefits. You could include a "Search Again" button in your results panel for example, then code itsClick
event very simply to hide the results panel and display the search form panel. Because ofViewState
, your search form is automatically filled in with the user's previous search values, which can be a very helpful thing for the user. In the world of classic ASP, that's a tricky thing to develop, but in ASP.NET it amounts to two lines of code (hide results panel, display form panel). Just some food for thought. :cool: