locked
Help with injecting javascript via Append into PopupControlExtender RRS feed

  • Question

  • User142627323 posted

    Hi,

    I was hoping someone could help with an issue I'm stuck on.

    I have a page with a grid view that the user can hover over an image within the row and it will retrieve additional information from the database and show it in a panel called by the PopupControlExtender.

    I then wanted to add a bing map showing the location within the same panel.  This also works correctly EXCEPT I can't seem to get the map to show automatically.  If I add a Mouseover or click event it works, but no matter what I try (inline, function, etc.) I can't get it to show when the panel shows.  The user has to take action for it to appear which is not what I want.

     

    Here is the section of code with the bolded section the code that is problematic:

    Again - I just want the Mouseover requirement removed so that the map will show without further input

     

    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
        public static string GetDynamicContent(string contextKey)
        {
            string[] strArrayVal;
            string CK;
            strArrayVal = contextKey.Split(',');
            string w1;
            w1 = strArrayVal[1];
            CK = strArrayVal[0];
            StringBuilder sTemp = new StringBuilder();
            DateTime LocateDate = DateTime.MinValue;
            string Lat1 = String.Empty;
            string Long1 = String.Empty;

            string connStrElite = ConfigurationManager.ConnectionStrings["ELITEConnectionString"].ConnectionString;
            SqlCommand cmdELITE = new SqlCommand("MSP_GetGPSID", new SqlConnection(connStrElite));
            cmdELITE.CommandType = CommandType.StoredProcedure;
            cmdELITE.Parameters.Add("@nID", SqlDbType.NVarChar, 36);
            cmdELITE.Parameters["@nID"].Value = Convert.ToInt32(CK);
            cmdELITE.Connection.Open();
            SqlDataReader Rdr = cmdELITE.ExecuteReader();

            while (Rdr.Read())
            {
                if (Rdr.HasRows)
                {

                    Lat1 = Convert.ToString(Rdr["LATITUDE"]);
                    Long1 = Convert.ToString(Rdr["LONGITUDE"]);
                    LocateDate = Convert.ToDateTime(Rdr["created"]);
                
                }
            }
            cmdELITE.Connection.Close();
            cmdELITE.Connection.Dispose();

       
           sTemp.Append("<table width='525'>");
          sTemp.Append("<tr><td><span class='textsmall'><b>Location Information for ID: " + w1 + "</b></span></td></tr>");
            sTemp.Append("<tr><td><span class='textsmall'>Lat/Long: " + Lat1.ToString() + ", " + Long1.ToString() + "</span></td></tr>");
           sTemp.Append("<tr><td><span class='textsmall'>Date: " + LocateDate.ToString() + "</span></td></tr>");
           sTemp.Append("<tr><td>");

     sTemp.Append("<a href=\"#\" onMouseOver=\"map = new VEMap('myMap'); map.SetDashboardSize(VEDashboardSize.Small); map.LoadMap(new VELatLong(" + Lat1.ToString() + ", " + Long1.ToString() + "), 16, 'h', false);var pin = new VEPushpin(1,new VELatLong(" + Lat1.ToString() + ", " + Long1.ToString() + "),'../Images/car2.gif','label');map.AddPushpin(pin);\">Show Map</a>");
        
            sTemp.Append("</td></tr></table>");
          
            return sTemp.ToString();
          
        }

     

    Thanks!

     

    Tuesday, January 18, 2011 3:51 PM

Answers

  • User1509044783 posted

     sTemp.Append("<a href=\"#\" onMouseOver=\"map = new VEMap('myMap'); map.SetDashboardSize(VEDashboardSize.Small); map.LoadMap(new VELatLong(" + Lat1.ToString() + ", " + Long1.ToString() + "), 16, 'h', false);var pin = new VEPushpin(1,new VELatLong(" + Lat1.ToString() + ", " + Long1.ToString() + "),'../Images/car2.gif','label');map.AddPushpin(pin);\">Show Map</a>");
     

    You may try wrapping all the content of OnMouseOver in a function by javascript. function loadmap () {

        map = new VEMap();

        ...

    }

    If you work at code-behind, you may use RegisterStartupScript to concat your string.

    Then, assign it to PopupControl's CommitScript property

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 24, 2011 3:16 AM