Often there is a need to generate JavaScript instructions in server-side ASP.NET code and send them to the client for execution. But what if you need to run that server-generated JavaScript code within client Page Load event (here I am talking about ASP.NET AJAX pageLoad(sender, args) event, but it applies to generic body.onLoad event as well).
Continue reading →
Tag Archives: workaround
Infragistics WebDataMenu: Expanding context menu UP
Infragistics WebDataMenu is a light-weight highly responsive menu control with rich server and clinet side model. I was using it to display context menu on right mouse click. The code is pretty simple:
function onMouseClick(oEvent) { if (oEvent.button == 2) { //right mouse button clicked var menu = $find("xwdmMyMenu"); menu.showAt(null,null, oEvent); } }
It checks whether the right mouse button was clicked (line 2) then locates the menu object and shows it using showAt method (which accepts 3 parameters, either X and Y client coordinates, or event object from which it derives coordinates of the mouse click).
It’s all well and good, but the problem is – menu always shows down from the location of the mouse click. And if the click is at the bottom of the screen – menu gets cut off:
I needed to make menu expand UP and couldn’t find a build-in property or method that would change this behaviour (GroupSettings.ExpandDirection property had no effect). Time for a little hack. Continue reading →
WebDialogWindow – removing IFRAME border in IE
Infragistics WebDialogWindow control is a flexible and lightweight AJAX dialog control designed to look and feel like standard Windows dialogs. One of its neat features – it allows to load the content from an external URL. In that case it renders the content inside of an IFRAME, which is all good and well, but leaves an ugly default iframe border.
Browsers like FireFox can remediate this by simple setting the “frameborder” attribute of the content pane IFRAME element:
function showDialog() { var oDialog = $find('xwdwMyDialog') var oDialogContent = oDialog.get_contentPane(); var oDialogIFrame = oDialogContent.get_iframe(); // Removing IFRAME border in FireFox oDialogIFrame.setAttribute('frameborder', '0'); oDialog.show(); }
but unfortunatelly this doesn’t work in IE. Continue reading →
Setting DOM element height and width thru style in IE and Firefox
I was using a pretty standard line of JavaScript code to set dimentions of an HTML element, something like:
oDiv.style.height = iWindowHeight/2 - 50;
It was working fine in IE, but had no effect whatsoever in Firefox.
Turned out all that was needed – to add ‘px’ to that line:
oDiv.style.height = iWindowHeight/2 - 50 + 'px';
and it works fine in both browsers.
Correcting “ASP.NET AJAX client-side framework failed to load” error
If you’re trying to use ASP.NET AJAX features (like Script Manager or Update Panel) in your ASP.NET 3.x website and getting “ASP.NET AJAX client-side framework failed to load” error, chances are your Web.config file is missing required sections. Fastest way to correct this is to create a new ASP.NET website in Visual Studio (you can delete it afterwards) and copy missing sections from the new web.config to the one in your web site.
Update: As churawut pointed out missing .AXD mapping in IIS configuration is another common source of this error (often this is done as security hardening on the IIS). I encountered it while researching missing images in ASP.NET charts, and found out that underlying reason was missing/corrupt .AXD mapping in IIS.
T-SQL String Aggregate in SQL Server
T-SQL dialect of SQL doesn’t have aggregate functions for strings, but there is an easy workaround using magic of XML.
Consider Employees table of the Northwind database. When I run following query:
SELECT Country, FirstName FROM Employees ORDER BY Country, FirstName
I get following result:
Country FirstName UK Anne UK Michael UK Robert UK Steven USA Andrew USA Janet USA Laura USA Margaret USA Nancy
Now I want to combine first names into comma separated strings grouped by country. Continue reading →
Global Chart Type for Dundas Chart Control
Dundas Charts for .NET has many cool features like async callbacks, AJAX scroll and zoom, plenty of chart types and great visuals, but in some cases some of those features could turn out to be more of a burden than useful. One example – the ability to set chart type for each individual series of a chart. This offers great flexibility in building combination charts (you can display column and line on the same chart to reflect different series’ data), but you’re losing the Infragistics simplicity of just setting the chart type and binding chart to data without worrying about appearance of each individual series.
This is especially inconvinient if you load chart appearance (including series appearance and chart type) from an external template. If you want to use chart type from the template, but feed it your own data – you’re stuck. But there is a solution. Continue reading →
ASP.NET accessing session variables in class modules
Sessions are a great way to share variable across your entire application, but they’re not accessable directly in class modules since they’re outside of page scope. So if you try something like Session(“VariableName”) = value inside of your class, you will get an error.
Fortunately there is a way. Thru HttpContext.Current notation available such common properties as Session, Server, Application, Cache. So to access your session variable inside a class just use HttpContext.Current.Session(“VariableName”) = value
Fixing WordPress 2.7 broken permalinks
When I moved this blog from former IIS to this Apache hosting I wanted to enable “pretty” permalink structure /year/month/day/topic, knowing that mod-rewrite was installed and active. But when I did that – every link resulted in 404 “Not Found” error. Trying to find solution I in WordPress support forums or even googling it was to no avail.
Finally I realised that when WordPress was enabling new link structure, for some reason it wasn’t writting rewrite rules into .htacess file. So, I put them there manually:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]
And it worked.
Group By and Aggregates in .NET DataTable
Often there is a need to perform group by operations on in-memory .NET data tables. You can’t run a standard SQL statement and LINQ is not available prior version 3.0 of .NET. To compensate for this shortcoming I put together a small function that works in .NET 2.0. As input parameters it accepts source DataTable, column name to group by and a column name to perform aggregate operation on. It returns a grouped data as data table:
Function GroupBy(ByVal i_sGroupByColumn As String, ByVal i_sAggregateColumn As String, ByVal i_dSourceTable As DataTable) As DataTable Dim dv As New DataView(i_dSourceTable) 'getting distinct values for group column Dim dtGroup As DataTable = dv.ToTable(True, New String() {i_sGroupByColumn}) 'adding column for the row count dtGroup.Columns.Add("Count", GetType(Integer)) 'looping thru distinct values for the group, counting For Each dr As DataRow In dtGroup.Rows dr("Count") = i_dSourceTable.Compute("Count(" & i_sAggregateColumn & ")", i_sGroupByColumn & " = '" & dr(i_sGroupByColumn) & "'") Next 'returning grouped/counted result Return dtGroup End Function
The function first gets distinct values for group-by column, by creating a data view from source data table and using DataView’s “ToTable” method. It then loops thru these distinct values performing aggregate function on the source table using DataTable’s “Compute” method – Count in this case, but it can easily be replaced with other aggregates.