April 13, 2011 at 3:56 am
Is there any way to pass variables from javascript in a web page to an SQL routine? I am using a navigator.geolocation javascript routine to get the gps location of IP addresses accessing my web site and I want to store these in an SQL table. I cannot figure out how to pass these variables to an SQL table in my apsx C# program. It probably isn't possible but I thought I would ask anyway.
April 13, 2011 at 5:53 am
yes and no;
javascript in and of itself can't do it alone; it requires a postback to the server;
so you need to either use a form post (submitting the whole aspx page) or use ajax to return some portion of the data, which typically might update the innerHtml of some object;
google a little for "javascript ajax postback" for examples like this:
http://www.keylimetie.com/Blog/2007/12/3/How-to-make-an-AJAX-Postback-with-JavaScript/
Lowell
April 13, 2011 at 6:54 am
would hidden fields on your web page help? store the values in the hidden field using javascript, and then access them in c#.
April 13, 2011 at 2:48 pm
Since you are just capturing IP location and looking up the gps location you could probably do that faster and more efficiently directly in your c#. Capturing the IP is painless and there are plenty of services (many of them free) to capture gps coords. This gives you the added benefit that even if they have disabled javascript you still capture their info. 😉
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply