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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Passing variables from JavaScript to ASP C#

  • 07-03-2007 1: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