Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Passing variables from JavaScript to ASP C#

Options
  • 07-03-2007 2:17pm
    #1
    Registered Users 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 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 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