I recently got a Lenovo ThinkPad W510 laptop, which is a bit of a beast (PC Advisor Review). There's an Intel Core i7 CPU running at 1.73 GHz, 3GB RAM and a nice 15.6" LED Screen. It's very well put together and feels like it will last for a long time, especially with the hard disk shock detection technology which turns off your hard drive if the chassis detects that the machine is dropped onto the ground
However, I had an issue with the laptop where it would make a constant high pitched squealing noise, almost so high pitched that only dogs would hear it, but unfortunately not quite.
I thought I could live with it but when you're sitting next to it for 7-8 hours a day and the sound is drilling into your mind, it becomes quite annoying. But fortunately, unlike many others who had the same problem, the answer proved to be achievable without making any support phone calls or having any parts replaced.
There's a very comprehensive suite of Lenovo settings which are preinstalled on the machine, and in particular there's an application called Power Manager.
Since it's a high performance machine designed for development or graphics editing and therefore has heavy battery usage by default, it gives you fine grained control over the balance between performance and power. You can slow down the CPU, dull the screen and switch off optical drives if you're running on battery power, and when you're on AC you can disable all that and let it run at full tilt.
These types of controls are nothing new, but in there was the answer to my squealing problem.
As part of Power Manager, there's a setting called 'Deep Sleep' which is some kind of CPU power management function. This was the cause. So I created a new 'power management profile' within the Power Manager applet and set Deep Sleep to off, then saved it.
After activating my new profile, the noise immediately went away! Thank goodness for that, because I had to get rid of the noise one way or another before it drove me nuts.
Tuesday, 31 August 2010
Solved: Lenovo ThinkPad W510: High pitched squealing noise
Posted by Phil Reid 12 comments
Labels: Lenovo W510, tech problems, tech review
Monday, 30 August 2010
Rounded Corners
I was asked to put some content inside a box shaped element which had rounded corners. Not square corners, it had to have rounded corners.
Unfortunately, since HTML is so 'boxy' this behaviour does not come naturally. It's not just a setting on your table or div element, and there's no particularly easy way to achieve this effect.
Until CSS3 and its border-radius property comes into play in all of the next generation browsers, creating a screen element with rounded corners needs to be done another way. More info on border-radius and browser support is available on CSS3.info.
I found that the effect can be achieved using images and divs. There's a nice article on the Webcredible site which gives you a step by step tutorial on exactly how to do it.
N.B: Being honest, you can actually use browser specific properties such as '-moz-border-radius' to display rounded corners, but I couldn't find the equivalent for IE which is no good since a large chunk of users will be using IE.
Posted by Phil Reid 0 comments
Labels: browsers, css, css3, web design
Monday, 23 August 2010
ASP.NET Error: "The DataSource does not support sorting"
In one of our projects we had a GridView which was by default bound to an ObjectDataSource to allow us to Sort/Page and to apply custom filtering. But we also needed to be able to search the data which the GridView is bound to, which we achieved in code and then databound the GridView to the resulting DataTable.
Here's a code snippet:
Before
grdvSummaryGrid.DataSourceID = String.Empty
Dim _clientBLL As New ClientBLL()
grdvSummaryGrid.DataSource = _clientBLL .Search(e.SearchText)
grdvSummaryGrid.DataBind()
Using this code, a problem arose where if you sorted the GridView and then carried out a search, an error resulted when the code attempted to DataBind it to the resulting table:
"System.NotSupportedException: The data source does not support sorting"
I tried a few things and considered creating an ObjectDataSource in code with the search results and then binding the GridView to that, but the answer turned out to be simple.
Before setting the DataSourceID of the GridView to an empty string to allow you to set its DataSource to the resulting DataTable (you can't set both properties), you clear the sort expression.
Like this:
After (Notice the new first line)
grdvSummaryGrid.Sort("", SortDirection.Ascending)
grdvSummaryGrid.DataSourceID = String.Empty
Dim _clientBLL As New ClientBLL()
grdvSummaryGrid.DataSource = _clientBLL .Search(e.SearchText)
grdvSummaryGrid.DataBind()
That did the job. Lots of people seem to have had this problem too, so hopefully this answer will be useful.
Posted by Phil Reid 3 comments
Labels: asp.net, GridView, tech problems
Saturday, 21 August 2010
ASP.NET: Sorting a DataTable
I was pulling out a DataTable from my database and applying some sorting to it in the Stored Procedure, which of course worked as expected.
But I needed the user to be able to pull a row out from a GridView, edit its fields and then reinsert it to the GridView, all the time preserving the sort order.
As usual, I went round the houses looking at all the usual crappy solutions that others who also forget to read the documentation come up with, until I found a simple solution that worked for me:
dataTable.DefaultView.Sort = "date_of_birth asc"
Simples!
Here's the MSDN documentation.
Posted by Phil Reid 0 comments
Wednesday, 18 August 2010
CSS: RadioButtonList Layout
For the most part, I love web development, but there are some things that I absolutely detest about it.
For example, something that should be straightforward such as getting horizontal radio buttons to appear in a neat and tidy way can be tough. Obviously your radiobutton labels will have different values and will therefore cause the list to have different widths - this can be messy if you have a few rows of radiobuttons.
In addition, the radiobutton label will by default wrap down to underneath the radiobutton itself which is hideous. That needs to be fixed.
You could try laying the controls out with a table or a series of fixed size divs, but you shouldn't need to. And using tables could be nasty.
CSS to the rescue! Create a class to use for your RadioButton controls and assign it.
.radioButtons {
border:none;
border-collapse:separate ;
}
.radioButtons input {
float:left;
}
.radioButtons label {
margin-left: 25px;
display: block;
}
.radioButtons td{
min-width:175px;
}
Then just lay out your control like this (an ASP RadioButtonList control is used here but you could use HTML literals too I guess):
<asp:RadioButtonList ID="rblYesNoMaybe" runat="server" RepeatDirection="Horizontal"
CssClass="radioButtons" >
<asp:ListItem>Yes</asp:ListItem>
<asp:ListItem>No</asp:ListItem>
<asp:ListItem>Maybe</asp:ListItem>
</asp:RadioButtonList>
Using this, you should find that your RadioButtons look better and that your label text doesn't wrap underneath the radiobutton input. You'll probably need to set the min-width property of the td to an arbitrary value to suit your page or site.
Posted by Phil Reid 0 comments
Labels: css, web design
Saturday, 26 June 2010
ASP.NET: Inserting NULL Values Into SQL Server Database
I literally almost destroyed a laptop today when trying to get around the fact that empty dates in my application were being stored in SQL Server as the completely useless '1900-01-01 00:00:00.000'.
Note that SQL Server is not the issue here, it WILL insert a NULL value if it's told to. If you're seeing this 1900 date then it's coming from your application.
I'm using an XSD within my Visual Studio project, and therefore it auto-generates methods for each of the methods I define on my TableAdapters. I needed to get null dates into these methods and then into the database without the application passing the 1900 date to SQL Server.
I tried loads of different methods of checking the values, by trying to pass Nothing, SqlDateTime.Null or System.DBNull.Value where the date was empty, but to no avail, I either got cast errors or the database did the insert but continued to think we were at the dawn of the 20th century.
Finally, I figured it out, and really there are two ways of achieving this. One is to use a Typed DataSet, which allows you to use the autogenerated 'SetMyColumnNameNull()' method.
But I'm not using a typed DataSet for my database insert methods, rather I call the stored procedure methods in my BLL and pass in the values rather than a row object.
So anyway, the answer was this:
When passing your date to your method which calls your stored procedure, pass your dates as strings. Then in your code you can check them like this:
(System.ComponentModel.DataObjectMethodType.Insert, True)> _
Public Function InsertOrder(ByVal date_in_question as String)
Dim dateInQuestion As Global.System.Nullable(Of Date)
' Bust any empty dates
If date_in_question <> "" Then
dateInQuestion = CDate(date_in_question)
End If
' Do the Insert
Dim orderId As Integer = Adapter.db_Insert_Update_Order(dateInQuestion)
Return orderId
Now when the date is passed to the stored procedure's method, if no date is set then an empty date is passed and the database inserts a NULL value.
You might want a more robust way of parsing your dates etc etc, but this worked for me.
Hope I've provided enough detail.
Posted by Phil Reid 0 comments
Labels: asp.net, sql server, vb.net
Monday, 21 June 2010
ASP.NET FileUpload Control Inside an UpdatePanel
I put a FileUpload control inside an UpdatePanel and ran into some problems, as many others did.
Since the UpdatePanel does not do a full postback by nature (and therefore only partially refreshes the screen), the FileUpload control does not work straight away.
To get it to work you need to add a PostBackTrigger which points at your Upload button. Here's a Microsoft example on that very topic.
Using a PostBackTrigger will cause a full postback to fire when a file is uploaded and will cause your control to work... in most cases.
However I found an odd issue where the file upload did not work the first time (the FileUpload control's HasFile property was always False) but it would upload successfully the second time.
I had to root around in a few places and eventually found the answer on StackOverflow's forums.
Turns out the answer is to define this in your Page_Load event:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Page.Form.Enctype = "multipart/form-data"
End Sub
After I added this, the FileUpload control started to work every time.
Posted by Phil Reid 0 comments
Labels: asp.net, fileupload control, tech problems
Monday, 14 June 2010
Syntax Highlighter Success
Finally, I managed to get SyntaxHighlighter working.
I had tried a few things previously, but it seems that some of the tutorials I had seen were based on older versions. The joy arrived when I found this post.
Now I can post code snippets in a way which is actually readable!
SELECT
COUNT(dbid) as TotalConnections
FROM
sys.sysprocesses
WHERE
dbid > 0
Hurrah!
I'm still using Stanley Shilov's utility to escape my HTML so that I can post using these simple tags:
<pre class="brush: html">
</pre>
Posted by Phil Reid 2 comments
SQL Server 2005: Determining the Total Number of Open/Active Connections
Sometimes applications can become unresponsive or generate SQL Server timeout exceptions (System.Data.SQLClient.SQLException: Timeout Expired) and sometimes you just need to find out how much traffic is hitting your database.
You can find out a few things by using these commands:
Total Number of Connections by Database
SELECT
DB_NAME(dbid) as DBName,
COUNT(dbid) as NumberOfConnections,
loginame as LoginName
FROM
sys.sysprocesses
WHERE
dbid > 0
GROUP BY
dbid, loginame
Total Connections
SELECT
COUNT(dbid) as TotalConnections
FROM
sys.sysprocesses
WHERE
dbid > 0
Detailed description of all running processes
sp_who2 'Active'
NB: You probably need to be logged in with SA privileges to run these commands.
Posted by Phil Reid 0 comments
Labels: sql server
Wednesday, 9 June 2010
ASP.NET: ListView Control and Nested ListViews
I have grown to love (in a purely sensible way) the ASP.NET ListView control. It's very flexible and gives you a lot of control over how you display your data on your site.
I needed to display on a summary screen not only the orders belonging to a specific customer, but the products belonging to each order. So I built a ListView to display the orders, then nested another ListView inside it which displays the products belonging to that order.
After some rooting around on the net, I found this excellent tutorial for nesting ListViews that I'll definitely be revisiting in future.
Posted by Phil Reid 0 comments