Archive for June, 2011

Bing Maps Pushpin appearing below where they should be

I was working the Bing Maps, adding a custom pushpin to a map, and the pushpin was being added below the point on the map I was clicking on. Which was frustrating, until I figured out the anchor parameter to the Pushpin constructor. With that parameter, you can adjust where the pin added, like so:

var pin = new Microsoft.Maps.Pushpin(loc, { icon: ‘/Images/MyIcon.png’, height: 15, width: 15, anchor: new Microsoft.Maps.Point(8, 8) }); 

That worked for my test pages, but when I moved it into my “production” site, it didn’t. It was better, but still not what I needed. Since I know the suspense is killing you, the problem was actually my style sheet. I had a <div> tag surrounding all my elements, and this element used the “page” class in my style sheet:

.page
{
    background-color: #fff;
    margin: 10px 10px 0px 10px;
    border: 1px solid #496077;
}

After I removed the style, the Pushpins appeared correctly. My theory is that the margin was pushing the pin from the position it should have been, but I’ll have to do some experimenting to be sure.

Leave a comment

Error: Row not found or changed

There I was, minding my own business, when I got this message:

Row not found or changed.

Apparently, my LINQ to SQL objects were rebelling, and I needed to put the smackdown on them. (I found not one, but two useful posts on it.) I did that by adding the “UpdateCheck = UpdateCheck.Never” to each of the properties in the designer.cs file, under the dbml file, that declared all the wonderful things inside my object model. So here is an example of one of the properties after I made the change:

[Column(Storage = "_ImageText", UpdateCheck = UpdateCheck.Never, DbType = "NVARCHAR(1000)", CanBeNull = false)]
  public string ImageText
  {
   get
   {
    return this._ImageText;
   }
   set
   {
    if ((this._ImageText != value))
    {
     this.OnImageTextChanging(value);
     this.SendPropertyChanging();
     this._ImageText = value;
     this.SendPropertyChanged("ImageText");
     this.OnImageTextChanged();
    }
   }
}

Leave a comment

Clearing checkboxes in a RadGrid

I was working with a Telerik RadGrid control and needed to clear out the CheckBox controls that made up one of the fields of the grid. I had tried to clear the checkboxes in two different places, first in the Button control that fired off a post back, and second, in the Page_Load event. Neither of these worked. Then I came across a post on the Telerik forums that pointed me in the right direction.

My problem wasn’t with the code that cleared the checkboxes, it was with where I was putting that code. The right place to put it was in the ItemCreated event:

public void gridFiles_ItemCreated(object sender, GridItemEventArgs e)
{
     for (int i = 0; i < gridFiles.Items.Count; i++)
     {
          CheckBox Check = (CheckBox)gridFiles.Items[i].FindControl("cbFile");
          Check.Checked = false;
     }
}

Leave a comment

Aligning text on a Bing Maps Pushpin

I was messing with Bing Maps, trying to add text to Pushpins. It was fairly simple to do, just add the “text” property to the Pushpin constructor:

var pin = new Microsoft.Maps.Pushpin(loc, { icon: ‘/Images/Pushpin.png’, height: 40, width: 40, text: ’99’ });

But the text, 99, was aligning high on the Pushpin, so the top part of my text was being cut off. And it looked ugly. So after a little research, I found the textOffset property. Adding this property to the constructor allowed me to align the text just like I wanted:

var pin = new Microsoft.Maps.Pushpin(loc, { icon: ‘/Images/Pushpin.png’, height: 40, width: 40, text: ’99’, textOffset: new Microsoft.Maps.Point(0,10) });

Notice that the textOffset property takes a Point. You can’t just go plugging values willy nilly, or chilly willy, or milly vanilly in there – you have to use a Point.

Leave a comment

Exception: Unable to evaluate expression…

I was working with the following code, the tail end of code which allows the user to download a file:

try
{
Response.ContentType = "text/plain";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName + ".dat");
Response.ClearContent();
Response.Buffer = true;
Response.Write(objBuilder.ToString());
Response.End();
}
catch (Exception e)
{
 // Stuff
}

While running through this code, I received and exception at the Response.End line:

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Luckily, I ran cross a very useful post on the ASP.NET forums which pointed to the exact problem. I took out the try-catch block and that solved the issue.

Leave a comment