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. (SOLVED) Having problem showing just a section of a page.

(SOLVED) Having problem showing just a section of a page.

Scheduled Pinned Locked Moved ASP.NET
helphtmldatabasequestion
3 Posts 2 Posters 16 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.
  • S Offline
    S Offline
    samflex
    wrote on last edited by
    #1

    Greetings again experts. Could you please help me out on this one. I have a very long markup page that is used for various activities. There is a section that allows users to enter a value into a search box and click the search button. If there is a hit, a page is populated with the values from the search hit. This works. If however, the search turns up nothing, then we would like to popup a section of the page with several form controls which allows user to enter the values that did not turn up during search and submit to the database. I tried using hide/show panel control but nothing is showing up. I tried hide and show div but no luck. I would truly appreciate any assistance with this. I am pasting only the section of the code that needs to be displayed in a popup, perhaps in the middle of the page. Many thanks in advance.

            Add Rebatable Toilets
            
                **How many toilets?**
                
                 
                   
                   <
    
    Richard DeemingR 1 Reply Last reply
    0
    • S samflex

      Greetings again experts. Could you please help me out on this one. I have a very long markup page that is used for various activities. There is a section that allows users to enter a value into a search box and click the search button. If there is a hit, a page is populated with the values from the search hit. This works. If however, the search turns up nothing, then we would like to popup a section of the page with several form controls which allows user to enter the values that did not turn up during search and submit to the database. I tried using hide/show panel control but nothing is showing up. I tried hide and show div but no luck. I would truly appreciate any assistance with this. I am pasting only the section of the code that needs to be displayed in a popup, perhaps in the middle of the page. Many thanks in advance.

              Add Rebatable Toilets
              
                  **How many toilets?**
                  
                   
                     
                     <
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      samflex wrote:

      Dim sqlStatement As String = "Select o.PrimaryFirst, o.PrimaryLast, ap.applicant, FORMAT(ap.DateReceived, 'd','us') as DateReceived,o.SecondaryFirst,o.SecondaryLast,ad.InstallAddress,ad.InstallCity, ad.InstallState, ad.InstallZip, ad.WaterAcctNo from Applications ap "
      sqlStatement += "inner Join Addresses ad on ap.WaterAccountNo = ad.WaterAcctNo inner join Owner o on ap.OwnerCode = o.OwnerID Where ad.InstallAddress Like '%" & address.Replace("'", "''").Trim() & "%'"

      Your code is almost certainly vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.

      Const sqlStatement As String = "Select o.PrimaryFirst, o.PrimaryLast, ap.applicant, FORMAT(ap.DateReceived, 'd','us') as DateReceived, o.SecondaryFirst, o.SecondaryLast, ad.InstallAddress, ad.InstallCity, ad.InstallState, ad.InstallZip, ad.WaterAcctNo from Applications ap inner Join Addresses ad on ap.WaterAccountNo = ad.WaterAcctNo inner join Owner o on ap.OwnerCode = o.OwnerID Where ad.InstallAddress Like @query"

      Using sqlCmd2 As New SqlCommand(sqlStatement, myConnection)
      sqlCmd2.Parameters.AddWithValue("@query", address.Trim())
      Using reader As SqlDataReader = sqlCmd2.ExecuteReader()
      If reader.HasRows Then
      div1.Visible = False
      While reader.Read()
      ' NB: Overwriting the contents of a single set of controls with the
      ' data from each record; you will only display the last record.

                  installationAddress.Text = String.Format("{0} {1}, {2} {3}", reader("InstallAddress"), reader("InstallCity"), reader("InstallState"), reader("InstallZip"))
                  waterAccountNumber.Text = reader("WaterAcctNo").ToString()
                  ownerInformation.Text = String.Format("{0} {1}", reader("PrimaryFirst"), reader("PrimaryLast"))
                  dateReceived.Text = reader("dateReceived").ToString()
                  applicantName.Text = reader("applicant").ToString()
              End While
          Else
              div1.Visible = True
          End If
      End Using
      

      End Using


      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        samflex wrote:

        Dim sqlStatement As String = "Select o.PrimaryFirst, o.PrimaryLast, ap.applicant, FORMAT(ap.DateReceived, 'd','us') as DateReceived,o.SecondaryFirst,o.SecondaryLast,ad.InstallAddress,ad.InstallCity, ad.InstallState, ad.InstallZip, ad.WaterAcctNo from Applications ap "
        sqlStatement += "inner Join Addresses ad on ap.WaterAccountNo = ad.WaterAcctNo inner join Owner o on ap.OwnerCode = o.OwnerID Where ad.InstallAddress Like '%" & address.Replace("'", "''").Trim() & "%'"

        Your code is almost certainly vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.

        Const sqlStatement As String = "Select o.PrimaryFirst, o.PrimaryLast, ap.applicant, FORMAT(ap.DateReceived, 'd','us') as DateReceived, o.SecondaryFirst, o.SecondaryLast, ad.InstallAddress, ad.InstallCity, ad.InstallState, ad.InstallZip, ad.WaterAcctNo from Applications ap inner Join Addresses ad on ap.WaterAccountNo = ad.WaterAcctNo inner join Owner o on ap.OwnerCode = o.OwnerID Where ad.InstallAddress Like @query"

        Using sqlCmd2 As New SqlCommand(sqlStatement, myConnection)
        sqlCmd2.Parameters.AddWithValue("@query", address.Trim())
        Using reader As SqlDataReader = sqlCmd2.ExecuteReader()
        If reader.HasRows Then
        div1.Visible = False
        While reader.Read()
        ' NB: Overwriting the contents of a single set of controls with the
        ' data from each record; you will only display the last record.

                    installationAddress.Text = String.Format("{0} {1}, {2} {3}", reader("InstallAddress"), reader("InstallCity"), reader("InstallState"), reader("InstallZip"))
                    waterAccountNumber.Text = reader("WaterAcctNo").ToString()
                    ownerInformation.Text = String.Format("{0} {1}", reader("PrimaryFirst"), reader("PrimaryLast"))
                    dateReceived.Text = reader("dateReceived").ToString()
                    applicantName.Text = reader("applicant").ToString()
                End While
            Else
                div1.Visible = True
            End If
        End Using
        

        End Using


        S Offline
        S Offline
        samflex
        wrote on last edited by
        #3

        Thank you very much sir.

        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