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. Client side validation using database values

Client side validation using database values

Scheduled Pinned Locked Moved ASP.NET
9 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.
  • S Offline
    S Offline
    snir_ya
    wrote on last edited by
    #1

    Hi, I'm trying to validate user input on the client side. The values needed for validating the user's input should come from the database where i have a RANGES table. I don't want to expose the user to the table but i want to use the table's values "behind the scene". Does anybody if and how this can be accomplished? Thakns a lot in advance. Snir.

    E 1 Reply Last reply
    0
    • S snir_ya

      Hi, I'm trying to validate user input on the client side. The values needed for validating the user's input should come from the database where i have a RANGES table. I don't want to expose the user to the table but i want to use the table's values "behind the scene". Does anybody if and how this can be accomplished? Thakns a lot in advance. Snir.

      E Offline
      E Offline
      enjoycrack
      wrote on last edited by
      #2

      hi there: You can use AJAX to do that... << >>

      8x Solutions Ltd

      S 1 Reply Last reply
      0
      • E enjoycrack

        hi there: You can use AJAX to do that... << >>

        8x Solutions Ltd

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

        thanks enjoycrack. Do you reckon it's the only possibility?

        R E 2 Replies Last reply
        0
        • S snir_ya

          thanks enjoycrack. Do you reckon it's the only possibility?

          R Offline
          R Offline
          RichardGrimmer
          wrote on last edited by
          #4

          Not at all - write some code to convert the dataset containing the values you want to a JSON string at page load, store it in a hidden field / session, then eval() it at the other end....

          "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

          S 1 Reply Last reply
          0
          • S snir_ya

            thanks enjoycrack. Do you reckon it's the only possibility?

            E Offline
            E Offline
            enjoycrack
            wrote on last edited by
            #5

            Nope Iam not sure this is the only posibilty...And you can dynamically generate script which depends on values from DB... Hope you get the idea... << >>

            8x Solutions Ltd

            1 Reply Last reply
            0
            • R RichardGrimmer

              Not at all - write some code to convert the dataset containing the values you want to a JSON string at page load, store it in a hidden field / session, then eval() it at the other end....

              "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

              S Offline
              S Offline
              snir_ya
              wrote on last edited by
              #6

              What's JSON string?

              R 1 Reply Last reply
              0
              • S snir_ya

                What's JSON string?

                R Offline
                R Offline
                RichardGrimmer
                wrote on last edited by
                #7

                Ahem...[^] Essentially, it's a text based description of an object.

                "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

                S 1 Reply Last reply
                0
                • R RichardGrimmer

                  Ahem...[^] Essentially, it's a text based description of an object.

                  "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

                  S Offline
                  S Offline
                  snir_ya
                  wrote on last edited by
                  #8

                  That's most helpfull richard. Now you're probably gonna sit back and watch me misinterpret what you just said... Cheers mate. Snir.

                  R 1 Reply Last reply
                  0
                  • S snir_ya

                    That's most helpfull richard. Now you're probably gonna sit back and watch me misinterpret what you just said... Cheers mate. Snir.

                    R Offline
                    R Offline
                    RichardGrimmer
                    wrote on last edited by
                    #9
                        public static string DataSetToJSON(DataSet ds)
                        {
                            string JSON = "{\\"Tables\\": \[";
                    
                            for (int i = 0; i < ds.Tables.Count; i++)
                            {
                                string tmp = DataTableToJSON(ds, "Rows", i);
                    
                                JSON += tmp;
                    
                                if (i < ds.Tables.Count - 1)
                                {
                                    JSON += " , ";
                                }
                            }
                    
                            JSON += "\]}";
                    
                            return JSON;
                        }
                    
                                public static string DataTableToJSON(DataSet ds, string dsName, int table)
                        {
                            string JSON = "{\\"" + dsName + "\\" : \[";
                            for (int i = 0; i < ds.Tables\[table\].Rows.Count; i++)
                            {
                                //add the row JSON bits...
                                JSON += "{";
                    
                                for (int j = 0; j < ds.Tables\[table\].Rows\[i\].Table.Columns.Count; j++)
                                {
                                    string columnName = ds.Tables\[table\].Rows\[i\].Table.Columns\[j\].ColumnName;
                                    string columnValue = ds.Tables\[table\].Rows\[i\]\[j\].ToString();
                    
                                    //Replace any crlf's in the column value...
                                    columnValue = columnValue.Replace("\\r\\n", ", ");
                    
                                    
                                    JSON += "\\"" + columnName + "\\": \\"" + columnValue + "\\"";
                    
                                    if (j != ds.Tables\[table\].Rows\[i\].Table.Columns.Count - 1)
                                    {
                                        JSON += " , ";
                                    }
                                }
                    
                                JSON += "}";
                                if (i != ds.Tables\[table\].Rows.Count - 1)
                                {
                                    JSON += " , ";
                                }
                    
                            }
                            JSON += "\]";
                            JSON += "}";
                    
                            return JSON;
                        }
                    

                    If it don't work, I don't care :)

                    "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

                    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