Author Archives: Yuriy

Regenerate JavaScript function code in ASP.NET partial postback after initial load

ASP.NET has a handy way of generating client side JavaScript code, but using it can be sometimes unpredictable. For example your client-side script needs to call function MyAlert, but the function itself is generated server-side on page load:

ClientScript.RegisterStartupScript(Me.GetType, "JSCode", _
                  "function MyAlert() {alert('This is the FIRST call')}", True)

Function is generated, and in due time, when needed is called by the client and the message “This is the FIRST call” is displayed. All is well.

Now, your page also has an UpdatePanel, and during a partial postback you need to modify that client-side function:

ScriptManager.RegisterStartupScript(Me, Me.GetType, "JSCode", _
                  "function MyAlert() {alert('This is the SECOND call')}", True)

In due time, when again needed by client code, function MyAlert is called and the message (wait for it, you’re in for a surprise) “This is the FIRST call” is displayed again. Originally generated function is called and second generation is ignored. Continue reading →

TSQL: Mix column names and ordinals in ORDER BY

It might be a weird scenario from a parallel universe, but in infinite dimensions it is bound to happen to someone else besides me. If you’re getting results from a query where you know some columns by name and others only by their ordinal position (e.g. if SQL is built dynamically and can change based on different condition) – you add sorting to that query by both ordinal position of a column and column name and even throw an expression into the mix. Allow me to illustrate:

Let’s get back to basics, namely Northwind database. If I ran a query like this:

SELECT * FROM Customers

I will get a result, similar to this:

Unsorted SELECT

Now to the weird part. Let’s say I need to sort this query by by Contact’s title and Contact’s last name. I don’t know what the column name for the Contact’s title will be, but I know if will always be a static 4th column. I don’t know where in the resultset Contact’s full name be located (it could be 3rd, or 8th or whatever column) but I do know it will always be called ContactName. Continue reading →

UltraWebGridExcelExporter: Export more than 65536 rows

When exporting data from Infragistics UltraWebGrid into Excel using UltraWebGridExcelExporter ordinary a very basic code similar to this is used:

'
' define Exporter "xMyExporter"
' define UltraWebGrid "xMyGrid" and load grid with data, then:
'
xMyExporter.ExportMode = UltraWebGrid.ExcelExport.ExportMode.Download
xMyExporter.Export(xMyGrid)

That’s it. But, if your data exceed 65536 rows you will get an error:

System.InvalidOperationException: The maximum number of rows in an excel worksheet with the current format is: 65536

This is not Excel Exporter limitation. Continue reading →

(Possible) solution for MSChart ArgumentException The image is not found error

If you’re using Microsoft’s .NET charting control on your ASP.NET pages you may receive an annoying error

[ArgumentException]: The image is not found. at
System.Web.UI.DataVisualization.Charting.ChartHttpHandler.ProcessSavedChartImage(HttpContext context) at
System.Web.UI.DataVisualization.Charting.ChartHttpHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I could be intermittent, sometimes happen, sometimes not. In your web.config you already set your temp images to be stored as files and not deleted after serving:

<add key="ChartImageHandler" value="storage=file;timeout=20;url=~/temp/;deleteAfterServicing=false" />

as well as trying other remedies and nothing helps.

One possible solution is, while still using file temp storage, instead of indicating relative path via url property set it to absolute path via dir property:

<add key="ChartImageHandler" value="storage=file;timeout=20;dir=C:\TEMP;deleteAfterServicing=false" />

In the example above C:\TEMP is an absolute path to the temp folder on the Web Server. In your case it could be different; in multi-server (WebFarm) environment it should be a network share, accessible by all servers.

Select Distinct DataRows from ADO.NET DataTable using LINQ

If you’re trying to retrieve distinct rows from your ADO.NET data table using code like

From oRow As DataRow In dtTable.Rows Select oRow Distinct

or

(From oRow As DataRow In dtTable.Rows Select oRow).Distinct()

You may find that rows that are being return are not unique. That’s because by default LINQ compares table rows by reference. If you need to compare by actual values – use DataRowComparer in Distinct method call:

(From oRow As DataRow In dtTable.Rows Select oRow).Distinct(DataRowComparer.Default)

‘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.

Speed up UltraWebGrid rendering on rebind

If you’re using Infragistics UltraWebGrid with it’s property Browser="Xml", you may find yourself living in a shotgun shack in a strange situation: When grid is rebinding – it takes (comparatively) short time to do server-side processing and then a very long time to render grid in the browser.

In my case it was most felt when grid (which had ViewType="OutlookGroupBy") was initially grouped with a lot of data in each group and then ungrouped back into flat view when user dragged last group column out. Using IE9 built-in developer tools I ran JavaScript profiler I found that culprit was Infragistics JS function “disposeNode” which was called numerous times and had worst both inclusive and exclusive execution time. Continue reading →

T-SQL String DeAggregate (Split, Ungroup) in SQL Server

A while back I posted a simple way to aggregate strings in SQL Server, but what if your task is opposite – you have a character-separated string values in your fields and you need to slice them into separate rows? Consider following scenario, you have a table:

CREATE TABLE #Employees (Country varchar(50), FirstNames varchar(50))

INSERT INTO #Employees(Country,FirstNames) 
	 VALUES ('UK','Anne,Michael,Robert,Steven')
INSERT INTO #Employees(Country,FirstNames)
     VALUES ('USA','Andrew,Janet,Laura,Margaret,Nancy')

SELECT Country, FirstNames FROM #Employees

That looks like this

Country  FirstNames
UK       Anne,Michael,Robert,Steven
USA      Andrew,Janet,Laura,Margaret,Nancy

and now you need to split FirstNames so that every FirstName is displayed on separate row. Continue reading →

SSRS viewer doesn’t work on IIS7 64bit

If you’re developing an ASP.NET application that utilizes Microsoft’s SSRS ReportViewer control, you may experience a weird behavior while trying to use it on 64 bit version of IIS7 (Windows Server 2008 or Windows 7) – nothing is displayed in the main report area and even icons, such as Print, Export aren’t rendering.

One possible cause for this – your application is using Application Pool with 32bit mode enabled. If so – disable it or switch to a different application pool. Chances are this will fix the above issue.