Using a combination of ASP.NET webpage and JavaScript, a dynamic webpage with a repe

I am new to using VB and integrating JavaScript. I have a simple question, but I'm having trouble figuring it out for some reason.

I am struggling to properly construct an IF-statement. Can you please help me? I have searched and googled, but have not found a solution that works for me. My code is functioning correctly otherwise. Here is the code I am working with:

<script type="text/javascript">
var markers = [
<asp:Repeater ID="rptMarkers" runat="server">
<ItemTemplate>
{
"title": '<%# Eval("pvm")%>',
"lat": '<%# Eval("lat")%>',
"lng": '<%# Eval("lng")%>',
"icon": '<%# Eval("Ikoni")%>',
"description": "<span style=’font-size:18px;font-weight:bold;><%#Eval("pvm")%> <%# Eval("Otsikko")%></span><hr>" +
"Text: <%# Eval("Nimi")%> <br> Merkki: <%# Eval("Tunniste")%> <br>"+
"<%# Eval("Info")%>"

--> This section should be within an IF-statement; If there is "Photo" information, it should be included, otherwise left out;

+"</div><div><img src=<%# Eval("Photo")%>  height='150'></img></div></div>"

<--

} </ItemTemplate> ...

Please provide me with some guidance on this issue.

Answer №1

If you're working with VB, this code snippet might help:

+
<% If (Eval("Photo") <> String.Empty) Then %>
    '</div><div><img src="<%# Eval("Photo")%>"  height='150'></img></div></div>'
<% Else %>
    ''
<% End if %>

UPDATE:

After the above code didn't work, here's a suggestion to simplify things by using a function with the necessary business logic. Here's an example:

Public Function GenerateMapData(pvm As String,
                                lat As String,
                                lng As String,
                                icon As String,
                                description As String,
                                text As String,
                                name As String,
                                identifier As String,
                                information As String,
                                image As String) As String

    Dim mapData As New StringBuilder("{")
    mapData.AppendFormat("""title"": '{0}',{1}", pvm, vbCrLf)
    mapData.AppendFormat("""lat"": '{0}',{1}", lat, vbCrLf)
    mapData.AppendFormat("""lng"": '{0}',{1}", lng, vbCrLf)
    mapData.AppendFormat("""icon"": '{0}'{1}", icon, vbCrLf)
    'insert any additional logic here
    mapData.AppendLine("}")
    Return mapData.ToString

End Function

You can then utilize the function like so:

<asp:Repeater ID="rptMarkers" runat="server" >
    <HeaderTemplate>
        var markers = [
    </HeaderTemplate>
    <ItemTemplate>
        <%# Me.GenerateMapData(Eval("pvm"), Eval("lat"), Eval("lng"), Eval("icon"), Eval("description"), Eval("text"), Eval("name"), Eval("identifier"), Eval("information"), Eval("image")) %>
    </ItemTemplate>
    <FooterTemplate>
        ];
    </FooterTemplate>
</asp:Repeater>

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

The utilization of "startIcon" and "endIcon" from the <Button/> API of Material-UI is restricted

I've been trying to work with this React code for a single component, but no matter what I do, I keep getting the same warning. I even tried copying and pasting the example, but the warning persists and the icon is not showing up. Can someone please a ...

Transmitting an email form using AJAX, Bootstrap, and Jquery

I am attempting to email a form using the code snippet below. This is a modified version of Bootstrap Validator created by 1000hz. $('#form').validator().on('submit', function (e) { if (e.isDefaultPrevented()) { alert("not workin ...

Using Javascript to save a numeric value and accessing it on a different webpage

I'm encountering an issue with a specific feature on my website. I want users to click on a hyperlink that will redirect them to an application form page. The challenge is ensuring that the reference number (a 5-digit code displayed as a header) is st ...

Retrieving localStorage data from another webpage

I recently created an account and I hope my question is clear. I have two separate pages on my website - one for a menu and the other for an HTML game. The menu has two buttons, one to start a new game and the other to continue from where you left off. How ...

Creating a dynamic drop-down menu using a single database table in CodeIgniter

Table https://i.sstatic.net/yw7d0.jpg I need the district names to dynamically change based on the Category selection. For example, when I select Category 1 from the drop-down, only the district names under Category 1 should be displayed, and the same fo ...

The elements within the array are being refreshed accurately, however, a separate component is being removed

I have developed a component that has the ability to contain multiple Value components. Users can add as many values as they want, with the first value being mandatory and non-removable. When adding two new Value components, I provide input fields for name ...

Losing a specific characteristic of data occurs when assigning a JavaScript object

After dedicating a full day to investigating this case, I found myself losing hope. const Tests = (state = INIT_STATE, action) => { switch (action.type) { case GET_TEST_DETAIL: return { ...state, test: {}, error ...

Communication between different windows using Chrome

I am facing an issue with my HTML5 Framework where the debugger is not visible in fullscreen mode due to the canvas taking up the entire screen. I need a solution where the debugger can be opened in another tab or popup so it can be moved off to another mo ...

The functionality of my website is currently experiencing difficulties when accessed through the Android UC Browser

My website, , is experiencing issues with product loading and the '+' button in the side menu not working on UC Browser. It works fine on other Android browsers like Chrome and Firefox, but I am confused as to why it is not functioning properly o ...

Ways to showcase a standalone identifier from iTunes RSS

I have a script below that fetches iTunes charts directly from the RSS and displays it. However, I am looking to only display the information for a specific ID from the RSS entry. Any suggestions on how this can be achieved? <script> jQuery(functi ...

Tips for importing a .geojson document in TypeScript using webpack?

I am trying to extract data from a .geojson file but faced some challenges while attempting two different methods: const geojson = require('../../assets/mygeojson.geojson'); The first method resulted in an error message stating: Module parse f ...

Experiencing Strange Issues with Jquery Image Carousel... Assistance Needed!

I recently created a jquery slideshow using a tutorial I found at this link: While the slideshow is functioning correctly for the most part, there is a strange issue that occurs right at the beginning when displaying the first image. Initially, the first ...

The issue lies in the error code TS2315 which states that the type 'observable' is not a generic

I keep encountering an error message that says 'observable is not generic' while importing files. I am working on implementing CRUD operations in Angular 7, where I have created two components for adding and listing employees. The functions for c ...

Set the style properties of one class to match the style properties of another class using JavaScript

I need to dynamically create a div using the Bootstrap panel for displaying it. The div's class will either be "panel panel-success" or "panel panel-danger" based on the server response, which can be either "success" or "failure." To assign the class ...

Using AJAX to Post Data with Relative Path in ASP.NET MVC 5

I have been developing an MVC 5 web application that utilizes AJAX Posts to invoke Controller Actions. For example, I have a controller named "Account" with an action called "Create". In my Account/Index view, which is rendered by accessing an Account/Ind ...

Switch out the Select feature for Checkboxes

Hey there! I'm currently trying to enhance the style and functionality of the Select checkboxes on my blog. However, when I change them to checkboxes, they lose their original function of searching for selected tags in each Select option. This issue i ...

Transferring a JavaScript element's ID to PHP

Recently, I came across a JavaScript function that automatically updates the date and time for me. I found the script on this URL: http://jsfiddle.net/pLsgJ/1/ setInterval(function() { var currentTime = new Date ( ); var currentHours = curren ...

JavaScript can be utilized to eliminate bootstrap tooltip attributes

Having trouble with adding and removing bootstrap tooltip attributes using JavaScript. The tooltip is added on mouseover, but not removed on mouseleave. The script adds the tooltip attributes on mouseover and should remove them on mouseleave. 'use s ...

Utilizing DateTime Values Binding within ASP.NET WebAPI (4.x Framework)

I'm struggling to comprehend the factors that determine how DateTime values are parsed by WebAPI's binding framework. Here is some sample code: public class TestSearchModel { public DateTime? From { get; set; } public DateTime? Until { ge ...

Are there any jQuery plugins available that animate elements as the page is scrolled?

Looking for a library that can create entry animations for elements as the page is scrolled? I previously used the animate it library, which was great - lightweight and easy to use. However, it doesn't seem compatible with the latest jQuery version (3 ...