Transferring/Sharing/Passing a variable/session state among aspx pages in C#

I'm struggling to figure out how to connect my map markers with data from a SQL server database. The idea is to display markers on the map, each containing information that can be clicked to navigate to a specific ASPX page. However, I'm facing difficulty in passing the required data between them. Any suggestions or guidance would be greatly appreciated!

The markers are generated using a repeater

<asp:Repeater ID="rptMarkers" runat="server">
                <ItemTemplate>
        {
            "title": '<%# Eval("LandmarkName") %>',
            "lat": '<%# Eval("LandmarkLat") %>',
            "lng": '<%# Eval("LandmarkLong") %>',
            "description": '<%# Eval("LandmarkDesc") %>',
            "id": '<%# Eval("LandmarkID")%>'
        }

Below is the accompanying JavaScript code

window.onload = function () {
                var mapOptions = {
                    center: new google.maps.LatLng(14.581, 120.976),
                    zoom: 12,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                var infoWindow = new google.maps.InfoWindow();
                var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
                for (i = 0; i < markers.length; i++) {
                    var data = markers[i];
                    var myLatlng = new google.maps.LatLng(data.lat, data.lng);
                    var marker = new google.maps.Marker({
                        position: myLatlng,
                        map: map,
                        title: data.title
                    });

                    (function (marker, data) {
                        var infotext = data.description + "<a href='#'>More Info</a>";
                        var id = data.id;
                        google.maps.event.addListener(marker, "click", function (e) {
                            infoWindow.setContent(infotext);
                            infoWindow.open(map, marker);
                            document.getElementById("landmark").value = id;
                        });
                    })(marker, data);

                }
            }
            google.maps.event.addDomListener(window, 'load', initialize);
            window.onload = InitializeMap;

Here's how the repeater gets filled

DataTable dt = this.GetData(sql);
       rptMarkers.DataSource = dt;
       rptMarkers.DataBind();

    }

    protected DataTable GetData(string query)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
        SqlCommand cmd = new SqlCommand(query);
        con.Open();
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con;

            sda.SelectCommand = cmd;
            using (DataTable dt = new DataTable())
            {
                sda.Fill(dt);
                return dt;
            }
        }
     }

In essence, the SQL query retrieves an ID which I intend to use to fetch data from the database in another ASPX page. I've attempted to utilize session state through a hidden input field, but haven't been able to get it functioning properly.

Thank you for any assistance provided! :D

Answer №1

Utilize querystring to include the landmark identifier in the URL when linking.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a dynamic menu structure by tailoring it to the specific elements found on each page

Currently, I am facing issues while attempting to generate a dynamic menu based on the elements present on the page. Is there a way to develop a menu using the following code structure?: <div class="parent"> <div class="one child" id="first"& ...

Error: The function subscribe in _store_js__WEBPACK_IMPORTED_MODULE_12__.default is not supported

In my main App component, I am subscribing to the store in a normal manner: class App extends Component { constructor(props) { super(props) this.state = {} this.unsubscribe = store.subscribe(() => { console.log(store.getState()); ...

Creating components in reactjs using the render function

Just a quick query – I've been diving into react js recently. Typically, when we create a component in React, we include the HTML template within the render function. I've noticed that most examples consist of small components with minimal HTM ...

Exploring the Depths of JSON Arrays within Typescript

I am faced with a challenge in extracting the value of the "id" from the following array of JSON data. The issue lies in the fact that the value is enclosed within double square brackets "[[" which are causing complications in retrieving the desired result ...

C# .NET Framework: Converting UTF-8 Bytes to Strings

Using C# programming language, I have developed an application that communicates with a server over a network using UDP sockets through the Enet library. One of the functions in my application is responsible for processing raw bytes sent in packets. This f ...

Block-level declarations are commonly used in TypeScript and Asp.net MVC 5

In my asp.net mvc5 project, I decided to incorporate TypeScript. I created an app.ts file and installed the nuget-package jquery.TypeScript.DefinitelyTyped. Here is a snippet of the app.ts code: /// <reference path="typings/jquery/jquery.d.ts"/> cl ...

Unable to access ASP.NET Core hosting on Ubuntu through client's browser

I am in desperate need of assistance as I attempt to develop a prototype app for my project on an Ubuntu server. However, every time I try to run the published .dll file, I am unable to access it from my client PC. Here is what I have done on my host (VM ...

I'm currently developing a Javascript quiz, but unfortunately, I am not seeing any outcomes. Can someone identify the issues in my code and provide guidance on what steps I should take next?

There are 3 requirements I must meet: The script should show the number of correct answers and the percentage of correctness at the end of the quiz. If all questions are answered correctly, display 'Well Done', or else display 'Try again&ap ...

Unable to access Angular $scope outside of the specified function

Just started diving into Angular and javascript. I've constructed a controller that uses a factory service to retrieve data from a local JSON file. The majority of my code is inspired by, or directly copied from this article by Dan Wahlin. I'm ha ...

How can data be displayed in AngularJS/Json without using ng-repeat?

It seems like I am required to use ng-repeat in order to display the data, but I would prefer to avoid using it. angular: App.controller('aboutLongCtrl', function ($scope, $http) { $http.get('test_data/ar_org.json') .then(func ...

Production environment sees req.cookies NEXTJS Middleware as undefined

Here is my latest middleware implementation: export async function middleware(request: NextRequest) { const token = request.headers.get('token') console.log(token) if (!token || token == undefined) { return NextResponse.redirect(new URL('/lo ...

Generating Words using JavaScript

I have been working on creating a word generator that prompts the user to input ten strings and then outputs a randomly selected one. However, instead of displaying the user input string, it is currently generating a random number. I am not encountering an ...

What steps should be taken in VUEjs if the API response is null?

There's a method in my code that retrieves a token from an API: let { Token } = await API.getToken({ postId: postId }) if(){} Whenever the token is null, I receive a warning in the console saying "Cannot read property 'Token' ...

How can the total price for a shopping cart be computed in React/Redux?

After extensive searches on Google and SO, I'm still coming up empty-handed when it comes to calculating the total price of items in a cart. Many tutorials stop at basic cart functionalities like "Add item to cart" or "increase/decrease quantity", but ...

My express javascript file is unable to recognize the environment variable I have set

Currently in my javascript file, I am attempting to store a key in an environment variable by using the following method: window.onload = function(){ (function getMap() { var locations = []; var key = process.env.$BING ....... continui ...

Switch the array's value if the key is a match?

I'm currently facing an issue where my code does not push the object when the key matches. How can I update the value of the key instead when there is a match? this.state.data.concat(items).filter(function (a) { return !this[a.key] && (th ...

How do I extract data from a JSON or JavaScript array with name/value pairs effectively?

I have a JSON array containing name/value pairs and I am searching for a more efficient way to update the value for a specific name in the array. For example: var myArr = [{"name":"start","value":1},{"name":"end","value":15},{"name":"counter","value":"6"} ...

Steps to add an item into an array and access specific properties of that item within the array:

I'm currently developing a blackjack game using Javascript, and I need to create objects for each card so that multiple cards add up to 10. My challenge lies in adding the values of these objects together when they are stored in an array. Here is the ...

Transfer all image files from Node.js to the frontend

What is the best way to send all image files from my backend nodejs server folder to my Reactjs client? I have set up a website where users can sign in and upload their files. However, I am facing an issue where only one file is visible on the client side, ...

Is there a way to retrieve a returned value from a `.ajax` request in the `done()` function in JavaScript?

Hey there! I've got a cool function that spits out the name of a person for you. Check it out below: function getName(ID){ return $.ajax({ url:url, data: ID, type: 'get', dataType: 'json' }) ...