Client side validation using database values
-
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.
-
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.
hi there: You can use AJAX to do that... << >>
-
hi there: You can use AJAX to do that... << >>
-
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
-
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... << >>
-
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
-
-
That's most helpfull richard. Now you're probably gonna sit back and watch me misinterpret what you just said... Cheers mate. Snir.
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