Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Process webform with many fields

Process webform with many fields

Scheduled Pinned Locked Moved ASP.NET
databasequestioncsharp
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xsoftdev2
    wrote on last edited by
    #1

    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

    M U 2 Replies Last reply
    0
    • X xsoftdev2

      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

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi Mike. The approach I would recommend is to code for the Click event of your submit button and construct a query using a Command-type object, like SqlCommand (if your database is SQL Server) or OleDbCommand. Add Parameter objects to your command to supply the values submitted from the user. Then use a DataAdapter object's .Fill() method to fill a DataSet (i.e. execute the query and retrieve the results), set your DataList's DataSource method to the DataSet, and execute the DataList's DataBind() 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.

      X 1 Reply Last reply
      0
      • X xsoftdev2

        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

        U Offline
        U Offline
        utsav_verma
        wrote on last edited by
        #3

        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

        X 1 Reply Last reply
        0
        • M Mike Ellison

          Hi Mike. The approach I would recommend is to code for the Click event of your submit button and construct a query using a Command-type object, like SqlCommand (if your database is SQL Server) or OleDbCommand. Add Parameter objects to your command to supply the values submitted from the user. Then use a DataAdapter object's .Fill() method to fill a DataSet (i.e. execute the query and retrieve the results), set your DataList's DataSource method to the DataSet, and execute the DataList's DataBind() 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.

          X Offline
          X Offline
          xsoftdev2
          wrote on last edited by
          #4

          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

          M 1 Reply Last reply
          0
          • U utsav_verma

            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

            X Offline
            X Offline
            xsoftdev2
            wrote on last edited by
            #5

            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

            U 1 Reply Last reply
            0
            • X xsoftdev2

              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

              M Offline
              M Offline
              Mike Ellison
              wrote on last edited by
              #6

              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, your Click event handler for the submit button hides the form panel, displays the results panel, constructs and executes the query, and sets the DataSource property for the DataList 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 your Click 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-in ViewState for controls, there are additional benefits. You could include a "Search Again" button in your results panel for example, then code its Click event very simply to hide the results panel and display the search form panel. Because of ViewState, 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:

              X 1 Reply Last reply
              0
              • X xsoftdev2

                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

                U Offline
                U Offline
                utsav_verma
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • M Mike Ellison

                  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, your Click event handler for the submit button hides the form panel, displays the results panel, constructs and executes the query, and sets the DataSource property for the DataList 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 your Click 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-in ViewState for controls, there are additional benefits. You could include a "Search Again" button in your results panel for example, then code its Click event very simply to hide the results panel and display the search form panel. Because of ViewState, 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:

                  X Offline
                  X Offline
                  xsoftdev2
                  wrote on last edited by
                  #8

                  Dear Mike Ellison, Excellent, thank you for your detailed post and it seems like a great idea which I shall implement. Thanks Mike

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups