Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Passing variables from JavaScript to ASP C#

  • 07-03-2007 02:17PM
    #1
    Registered Users, Registered Users 2 Posts: 463 ✭✭


    I'm trying to call a javascript function addLocation which is taking in a latitude & longitude (selected from a google map) read from text boxs and the location name from the user entered text box.

    The javascript function: addLocation is called. The variables are passed into it. Then what we want to do is take those variables, pass them into our asp code and insert it into our database.

    I'm not sure, however that the asp code within the javascript function is actually reading in the variables or even that the function is leading to the asp being executed at all.

    Any help would be much appreciated!
    function addLocation(lat, lng, locName) {
    <asp:SqlDataSource ID="AddLocation" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"
    InsertCommand="INSERT INTO [aspnet_Gazetteer] ([placeName], [longitude], [latitude]) VALUES (locName, lng, lat)"
    ProviderName="<%$ ConnectionStrings:ASPNETDBConnectionString1.ProviderName %>">
    <InsertParameters>
    <asp:ControlParameter Name="lat" Type="String" ControlID="lat" PropertyName="Text" />
    <asp:ControlParameter Name="lng" Type="String" ControlID="lng" PropertyName="Text" />
    <asp:ControlParameter Name="locName" Type="String" ControlID="locName" PropertyName="Text" />
    </InsertParameters>
    </asp:SqlDataSource>
    }


Comments

  • Registered Users, Registered Users 2 Posts: 872 ✭✭✭grahamor


    You might get more answers to this in the programming forum but ill try to answer anyway.

    You can have a standard html textbox to put your lat, long values in and then put a runat="server" as an attribute of the textbox. This means that in your code behind you can reference the values of this textbox

    i.e.

    <input type="text" id="txtLatitude" runat="server">

    in your code behind you can reference it like

    string lat = txtLatitude.value;

    I have recently done exactly what you described with a google map and a database so if you need any more help just ask.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    ^^ Pretty much what grahamor said. I'd also avoid putting SQL statements or any DB information into Javascript as it readable client side and that makes for a huge security issue.


Advertisement