Tag Archives: Quick fix

Keep animated images after uploading to WordPress

Haven’t written in a while. Not that nothing interesting happened, but never got around to. But I finally moved my blogs to AWS Lightsail (very smooth process, by the way) and experienced only one hurdle I wanted to write about (surprisingly, not related to AWS).

After the migration, I noticed that all images on my site lost their animation. When I inspected an image – I found that it’s source goes thru some kind of a proxy “i1.wp.com”. After digging a bit I found that it is used by JetPack site acceleration service – it caches images to serve them faster. Unfortunately cached copies seem to lose some of their properties (like animation).

To fix it – go to JetPack settings and turn “Speed up image load times” off

Jetpack settings

Happy blogging!

WriteEndObject of JSON.NET ouptuts NULL literal

JSON.NET is a very popular framework to process JSON data in .NET. We recently upgraded from v4 to v6 and noticed strange thing it started to output null to JSON strings created by JsonTextWriter object.

For example if JSON produced by v4 would look like this:

{"param1":"value1", "param2":"value2",
"someArray":[{"arrParam1": "arrValue1"}, {"arrParam2": "arrValue2"}]}

Same code, using v6, would prodcuce

{"param1":"value1", "param2":"value2",
"someArray":[{"arrParam1": "arrValue1"}, {"arrParam2": "arrValue2"}]null}

that extra “null” makes it invalid and unusable JSON.

The .NET function to create JSON writes it into a StringBuilder and is pretty straighforward.

  1. It starts with call to WriteStartObject method of JsonTextWriter
  2. Then it creates parameter name via WritePropertyName
  3. Depending on whether primitive value or raw string needs to be written WriteValue or WriteRaw methods are used respectfully
  4. Repeat steps 2 and 3 as needed
  5. Call to WriteEndObjectto finish writing.

This worked perfectly well when version 4 of Newtonsoft.Json.dll was used. After upgrading to version 6 last method – “WriteEndObject” began to output “null” to resulting JSON.

The solution is to use WriteRawValue method instead of WriteRaw – it still outputs raw string, but at the end WriteEndObject doesn’t output “null” anymore.

Reenable (temporary) showModalDialog support in Chrome (for Windows) 37+

You know you shouldn’t use showModalDialog to open modal windows – it’s bad taste and prone to cause issues. Unfortunately many applications (especially Enterprise ones) rely on the method ability to halt code execution until the window closed (e.g. user answers a YES/NO question).

Tough luck, starting version 37 Google Chrome removed support for showModalDialog. Your code suddenly began to act in weird and unpredictable way. You definitely should rework it to use a different approach to dialogs. Fortunately Google gives you a bit more time. You can re-enable showModalDialog support, but only temporarily – until May of 2015. Continue reading →

Infragistics WebDataGrid stalls on paging large datasets

A common scenario while using Infragistics WebDataGrid is to have an unbound column, whose cell’s value is determined at runtime in InitializeRow event, something like

Private Sub xmyGrid_InitializeRow(ByVal sender As Object, ByVal e As GridControls.RowEventArgs) Handles xmyGrid.InitializeRow
   '... some code
   e.Row.Items(0).Value = SomeCalculatedData
   '... some more code
End Sub

This works fine if you bind the grid to a small data set (and you should!) But if, due to circumstances out of your control, you bind it to a dataset with tens of thousand of records you might be screwed. Even if you enable paging (and you most definitely should!) you may find yourself living in a shotgun shack in a situation that changing page takes forever and eventually crashes. If you do – change the above line to

e.Row.Items(0).Text = SomeCalculatedData

note using of .Text property, which is String, instead of .Value which is Object. Since you’re assigning the calculated data for presentation only – no need to change underlying value – and this makes all the difference.

Solution for IE10 error: SCRIPT5022: Sys.ArgumentOutOfRangeException: Value must be an integer

If you’re testing your ASP.NET project in Internet Explorer 10, you may encounter following error:

SCRIPT5022: Sys.ArgumentOutOfRangeException: Value must be an integer.
Parameter name: (x or y)
Actual value was (some floating point value)
ScriptResource.axd, line … character …

Often it come up when you use some 3rd party libraries, Telerik or Infragistics (in my case it happened in WebDataMenu control).

Here why it happens. Continue reading →

Norton 360 Provides Security, Identity Protection, PC Tune-up, and More

Are you looking to secure your computer from the infectious viruses lurking on the Internet? Are you interested in getting your PC running as fast as possible? Are you hoping to protect your identity and keep your personal information safe from intruders and scammers who will stop at anything to steal it? If so, Norton 360 has everything you are looking. Norton 360 is the all-in-one security protection software produced by Symantec that works around the clock to protect not only your computer, but you, from potential security breaches that can happen without you having the slightest idea.

Norton 360 has been updated to find and kill the most serious viruses, implementing a five layer protection system that discovers and terminates threats faster than competing software. The threat removal layer digs deep into the confines of your system to get rid of treacherous threats and viruses, while the network defense layer works to stop threats before they can even reach your system. Meanwhile, SONAR technology and constant threat monitoring keep your system in-check and monitored at all times, so that threats that have reached your computer can be detected and put to rest before the effects become noticeable and threats that exist online are weeded out from web searches and search engines, disallowing you from finding them and reaping the consequences that can occur.

While all of this is going on quietly in the background of your computer, Norton 360 is keeping your personal information guarded and your files organized, fixing any other problems that may be occurring and compressing data to keep your system running lightning fast. The security suite can be installed on up to three computers and/or devices, with cloud management controlling all devices from a single, central unit. Norton 360 users also have the option of backing up and restoring files (documents, music, videos, photos, etc.), installing parental controls, scanning and updating at all times of the day, and so much more. Norton 360 has so much to offer to all its customers. If you haven’t yet purchased a subscription, what are you waiting for?

‘this.Column.Band’ is null or not an object error in UltraWebGrid filtering

When you filter Infragistics UltraWebGrid by clicking Filter icon in the column header – dropdown with filter values appears. Normally if you click elsewhere on the page – dropdown disappears. But sometimes it doesn’t, for example if you click an element that invokes a JavaScript function. Filter dropdown stays open and this could cause problems – when grid refreshes (and possibly other actions are performed) error is thrown:

‘this.Column.Band’ is null or not an object

The solution to this is to close filter dropdown ourselves. Put these lines into your client-side code whenever clicking outside the filter doesn’t close it:

var aGridCols = igtbl_getGridById('xMyGrid').Bands[0].Columns
   for (var I = 0; I < aGridCols.length; I++)
      aGridCols[I].showFilterDropDown(false);

Here we’re looping thru grids column collection (This example assumes grid is in Flat or OutlookGroupBy mode, if your grid is hierarchical, you will have to loop thru band collection as well). For every column we pass False to showFilterDropDown method which (probably showing Infragistics cute sense of humor) hides filter dropdown if it is open. If dropdown is hidden for the column already – nothing happens.

As a result opened filter dropdown is now always closed prior to previously offending action and the error doesn’t happen.

WebDataTree returns multiple selected nodes in single-select mode

This could be a bug in Infragistics WebDataTree control or it could be a very specific scenario (maybe it’s even by design, I don’t know) but here’s a weird behavior that I encountered. Using following code in WebDataTree’s event handler (oh and by the way, tree control is in a single-select mode):

Protected Sub xMyTree_SelectionChanged(ByVal sender As Object, ByVal e As NavigationControls.DataTreeSelectionEventArgs) Handles MyTree.SelectionChanged
   if e.NewSelectedNodes(0).Text = "Some Value"
      'do something with newly selected tree node
   end if
End Sub

I intended to use newly selected node to perform some operations. To my surprise e.NewSelectedNodes(0) referred to previously selected node (despite the name of the property) and newly selected value were located in e.NewSelectedNodes(1)! So the quick workaround was to use slightly modified code:

Protected Sub xMyTree_SelectionChanged(ByVal sender As Object, ByVal e As NavigationControls.DataTreeSelectionEventArgs) Handles MyTree.SelectionChanged
   if e.NewSelectedNodes(e.NewSelectedNodes.Count-1).Text = "Some Value"
      'do something with newly selected tree node
   end if
End Sub

This way it will always get latest selected node and the solution is universal. If the bug described above occurs – code will grab e.NewSelectedNodes(1) (because Count = 2). If the tree behaves as expected – code will get grab e.NewSelectedNodes(0) (because Count = 1)

@@ROWCOUNT is affected by IF statement

Let’s say you’re writing T-SQL code and need to make sure that your query returns one and only row. If no records returned – an error message needs to be shown. If more than one record is returned – another error message needs to be show. The code goes something like this:

-- ... query runs here and returns row

IF @@ROWCOUNT = 0 RAISERROR('No records found', 18, 1)
ELSE IF @@ROWCOUNT > 0 RAISERROR('More than one record found', 18, 1)

-- ... continue when exactly one row is returned

Now if your query returns 3 records you’d expect it to trip the second IF statement and raise error with correct message. Unfortunately this doesn’t happen. The reason being – the first IF statement resets @@ROWCOUNT to 0. So, to avoid this we need to preserve the @@ROWCOUNT value in a local variable:

DECLARE @iRowCount int

-- ... query runs here and returns row

SET @iRowCount = @@ROWCOUNT

IF @iRowCount = 0 RAISERROR('No records found', 18, 1)
ELSE IF @iRowCount > 0 RAISERROR('More than one record found', 18, 1)

-- ... continue when exactly one row is returned

This way count of rows returned by the query is saved and is not affected by any following statements.

UltraWebGrid: Hiding ServerOnly columns during export to Excel

If you’re using Infragistics UltraWebGrid with ExcelExporter and your grid has columns marked as “ServerOnly” – they’re visible in exported Excel worksheet even though the grid doesn’t show them onscreen. To hide these column in exported file, mark them as “Hidden” as well. This will have no additional effect on the way grid looks on screen, but the columns will be gone from the worksheet.