HTML <button> element causes double postback in Web Form

Very strange behavior observed today.

I placed <button> element on ASP.NET page and created OnServerClick event. The event was wired only once, everything worked properly etc.

Suddenly I discovered that from some reason its postback handler is called twice. This was not happening when page was opened directly in fresh new browser window (IE) but after navigating to it from any other page OnServerClick was called twice every click.

Moreover this behavior did not happen in FireFox.

I found the solution here: http://forums.asp.net/t/1465022.aspx

I added type=”button” to my <button> and it started to behave correctly.

Advertisements

Empty collections of GridViewUpdateEventArgs

In my code biding ASP.NET GridView to custom datasource I encoured a problem that during RowUpdating event collections of GridViewUpdateEventArgs: Keys, OldValues, and NewValues are empty.

After googling I find that the problem occurs only with custom datasource. When it is used collections are not popullated by the grid.

I needed NewValues collection to get user input from in-place grid editor. Found solutions recommended to access the controls directly by FindControl and query their properties. Anyhow I did not find easy way to get names of controls inserted automatically by the grid switching in the edit mode.

Finally, afte long searching in the web and trying various approaches I found this: http://bloggingabout.net/blogs/dennis/archive/2006/08/24/DataBinding-in-ASP.NET-2.0-and-the-RowUpdating-event.aspx

and ussed suggested trick to populate NewValues collection.

It worked and solved the problem.

protected void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    GridView gv = (GridView)sender;
    for (int i = 0; i < gv.Columns.Count; i++)
    {
        DataControlFieldCell cell = gv.Rows[e.RowIndex].Cells[i] as DataControlFieldCell;
        gv.Columns[i].ExtractValuesFromCell(e.NewValues, cell, DataControlRowState.Edit, true);
    }
    // do update of item here
    grid.EditIndex = -1;
    BindGridView();
}

System.Windows.Forms.TextRenderer draws blurry text when rendering to bitmap

Symptom:

Blurry text is drawn by TextRenderer class when rendering to device context associated with bitmap. It occurs at systems when ClearType is enabled.

How to fix:

Use TextRenderer.DrawText overloads requiring backColor parameter and pass them background color used for font aliasing.

How to install Polish XT9 dictionary at HTC Touch Cruise

I own Polish version of HTC Touch Cruise. Unfortunatelly the manufacturer did not equip this device with Polish XT9 dictionary which makes on-screen keyboard very hard to use.

Today I found working solution for this problem. Member of XDA-Developers forum published great post about how to transplant keyboard software from HTC Diamond device.

Short instructions:

  1. Download and unzip gullum diamond keys.zip and gullum Polish Diamond keys.zip.
  2. Copy both CAB files to your HTC Touch Cruise
  3. Run and install both CAB files (device will do soft reset after each installation)
  4. At your device open Start / Settings / Input (Start / Ustawienia / Wprowadzanie tekstu)
  5. Select “Touch Diamond Keyboard” as input method.
  6. Click Options button.
  7. Select Polish as input language.

More keyboards containing XT9 dictionaries are available for download from XDA-Developers forum. There are: Czech, Danish, Dutch, English, French, German, Finnish, Russian, Greek, Italian, Norwegian, Portuguese, Spanish and Swedish.

SQL Server stored ASP.NET Session variables are lost when switching web servers

Environment:

Cluster of multiple web servers (Microsoft IIS) connected through load balancer sharing ASP.NET session variables by using SQLServer mode of <sessionState> configuration.

Symptoms:

Session variables are randomly lost and recovered when switching between web servers. Depending on which web server handles the request session variables are different. Some web servers seems to share same set of variables. Others have different set of variables.

Reason:

All web site identifiers must be equal at all of web servers. They act as application identifier and each application have separate pool of session variables.

In my case five of six web servers had equal web site identifiers. The sixth server had different web site identifier. All requests redirected to it seen different session variables than accessible at other web servers.

To check web site identifier

  1. Open Start / Administrative Tools / Internet Information Services (IIS) Manager
  2. Navigate to (server name) / Web Sites
  3. Switch right pane of console to Details view.
  4. You will see columns: Description, Identifier, State, Host header value, IP address, Port, SSL Port, Status
  5. Read web site identifier from column “Identifier”
  6. Verify if all web servers have equal web site identifier.

To change web site identifier

  1. Stop the web site (right click at IIS manager and select Stop, there is no need to stop entire IIS).
  2. Open command line console and change current directory to “C:\Inetpub\AdminScripts”.
  3. Run following command:
    cscript adsutil.vbs move w3svc/currentid w3svc/newid
  4. where “currentid” is current web site identifier and “newid” is new web site identifier.
  5. Start the web site.

Files in PureCM workspace have invalid encoding

I’ve created a PureCM workspace for web site project. After starting up the site it turns out that all Polish characters are invalid. The site is made in UTF-8 and all files contains texts encoded this way.

The browser could not identify what kind of encoding is used. I’ve tried with ISO-8859-2 which is another possible standard for Polish characters.

No effects.

I’ve checked the file types reported by PureCM. For most of C# code files it was “text/plain” which we configured in repository with following options:

  • File Type: text
  • Selected “Disable writing of unicode identifier”
  • Encoding: System Encoding

What does “System Encoding” mean for PureCM?

It turns out that it is a setting for “non-Unicode programs” which can be found in system’s Control Panel / Regional and Language Options / Advanced.

I’ve created the workspace at new PureCM installation at computer running English Windows version and thas setting was “English” by default.

To solve the problem I did following steps:

  1. Opened Control Panel
  2. Opened Regional and Language Options
  3. Clicked to Advanced tab
  4. Selected “Polish” as Language for non-Unicode programs.
  5. Rebooted the computer.
  6. Deleted the PureCM workspace.
  7. Created PureCM workspace.

IIS does not want to start after change of IP

The IIS 6.0 installed at Windows 2003 Small Business Server refused to start. All web sites reported following error:

The format of the specified network name is invalid

Additionally in System event log following errors were logged:

EventID 1004 from W3SVC: Cannot register the URL prefix …. for site …. The site has been deactivated.

and

Event ID 1005 from HTTP: Unable to bind to the underlying transport for …. The IP Listen-Only list may contain a reference to an interface which may not exist on this machine.

I checked if IIS websites were configured to listen on old IP address only… but no… they were set to “All unassigned”.

Also I checked if nothing blocks ports 80 and 443 when IIS is stopped….

After some research I found this Microsoft TechNet page: Configuring the IP Inclusion List (IIS 6.0) which mentiones both events and refers to “httpcfg” utility which is used for configuration of HTTP protocol bindings.

Unfortunatelly I was working at remote desktop without access to installation CD to install Windows Support Tools containing “httpcfg”. But the solution was quite simple…

What I did to fix:

  1. Opened the Registry Editor
  2. Navigated to “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters”
  3. At “ListenOnlyList” registry value there was a reference to old IP address.
  4. Changed the old IP address to new one in “ListenOnlyList” value.
  5. Restarted HTTP service (“net stop http / net start http”)
  6. Restarted IIS service (“net stop w3svc / net start w3svc”)

And it works now…