Remove tab and new line space using RegularExpression in ASP.Net

Last Reply one year ago By Kibock

Posted one year ago

Dear All,

I am trying to implement Google Map using Repeater and SQL Database based on the article:

The Google Map is not displaying on web, unless I "cut and paste" the Description text directly from SQL database.

Here is the code:

<div id="dvMap" style="border: thin solid #87ceeb; width:100%; height:300px;"></div>

<script type="text/javascript">
    var markers = [
    <asp:Repeater ID="rptMarkers" runat="server">
                    "lat": '<%# Eval("PersonBruddLATITUDE") %>',
                    "lng": '<%# Eval("PersonBruddLONGITUDE") %>',
                    "title": '<%# Eval("PersonShipName") %>',
                    "description": '<%# Eval("PersonBruddDescription") %>'


<script type="text/javascript">

    window.onload = function () {

        var mapOptions = {
            center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
            zoom: 10,
            gestureHandling: 'greedy',
            mapTypeId: google.maps.MapTypeId.ROADMAP

        var icon = "";

        var infoWindow = new google.maps.InfoWindow();

        var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);

        for (i = 0; i < markers.length; i++) {

            var data = markers[i];

            var myLatlng = new google.maps.LatLng(, data.lng);

            var marker = new google.maps.Marker({ position: myLatlng, draggable: false, map: map, animation: google.maps.Animation.DROP, icon: new google.maps.MarkerImage(icon) });

            (function (marker, data) {

                google.maps.event.addListener(marker, "click", function () {

                    infoWindow.setContent("<div style = 'color:#12969b; font-weight:bold;'>" + data.title  + "</div>" + "<br>" + "<div style = 'color:#2d2625;'>" + data.description + "</div>" + "<br>");
          , marker);
            })(marker, data);

Code behind:

            if (!this.IsPostBack)
                DataTable dt = GetData("select * from brudd_Los where catID ='" + dataID.Text.Trim() + "'");
                rptMarkers.DataSource = dt;
<asp:TextBox ID="dataID" runat="server" > </asp:TextBox> 
<asp:Button ID="Ebutton" runat="server" onclick="Button1_Click" />

How to solve this issue?

Many thanks

You are viewing reply posted by: Kibock one year ago.
Posted one year ago

The error occurs because og the line space of 

txtPersonBruddDescription the in DB column.

Solution was to use in order to remove the line space before adding record to the DB:

string replacement = Regex.Replace(txtPersonBruddDescription.Text.Trim(), @"\t|\n|\r|""");