ASP.NET Cafe
new tricks every week

Javascript:void(0); may cause problems in old IE6

Saturday, 26 April 2008 10:46 by dmitriy

Just found VERY hard bug. The problem appears only in IE6, but some projects still support this browser. If you are using <a href="javascript:void(0);" >Button</a>

And attached OnClick event. You can encounter some really weird things (in event hadler, it works but some strange way). For me - I had to change src of some img tag. But after this no reload happened. Then I've used href="#" the problem was solved. Somebody knows more about these problems? 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:  
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Focusing controls from serverside with and without AJAX Extensions

Wednesday, 9 April 2008 09:03 by dmitriy

There is a thing that allows you to point user on the right place on page after postback. The secret is not a secret - just javascript focus() function called. But how to make this right using the ASP.NET framework. It's not a big deal... there are a function for this:

[code=C#]Page.SetFocus(top.ClientID);[/code]

And this works good in case of PostBack. But what going on if you are using partial postback ( using update panel of Ajax extensions )?
This does not work any more. But works this.

[code=C#]ScriptManager.GetCurrent(Page).SetFocus(top);[/code]

What also can you find useful ? Hmm...  sometimes it does not work. Why? 90% that are you trying to set focus on the Control that does not receive focus in browser.
Don't try to focus a Label. Focus Anchor tag if you need to focus a place on your page.

Usually peoples try to include javascript functions that do this job, but I think that this way is better.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Chess Titans from VISTA - 3 Queens on board.

Wednesday, 9 April 2008 03:51 by dmitriy

Just played Chess :) with 3 Queens.

If you want to make your own 3 queens. You need to: take a black queen and promote as much pawns as you want to Queens!

chess.jpg (96.25 kb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Main
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Running MySQL queries on MS SQL

Monday, 7 April 2008 12:23 by dmitriy

There are some difference in SQL syntax for MySQL and MS SQL. One of the differences is TOP and LIMIT keywords. And this is bad. Because LIMIT comes in the end of query and TOP comes in the beginning. So, simply to replace is not good. I'm missing the ability of LIMIT to use 2 parameters... but this is possible too, and you need to remember this and add this support if you find this code useful.

[code=c#;Simply approach to make MySQL queries work on MS SQL]/// <summary>
/// Converts MySQL "LIMIT" queries to MS SQL "TOP" queries
/// </summary>
/// <param name="q">Query</param>
/// <returns></returns>
public string MakeQuerySQLServerCompatible(string q)
{
    string res = q;
    Regex limit = new Regex("SELECT(.+)LIMIT (\\d+)", RegexOptions.IgnoreCase | RegexOptions.Singleline);
    Match m = limit.Match(q);
    if (m.Groups.Count == 3)
    {
        string beforeLimit = m.Groups[1].Value;
        string limitCount = m.Groups[2].Value;
        res = string.Format("SELECT TOP ({0}) {1}", limitCount, beforeLimit);
    }
        return res;
    }[/code]

This stuff is tricky, that's why I decided to post it. The idea to remove LIMIT stuff and replace it with SELECT TOP statement. These queries special abilities always on high demand because almost every query should define the max amount of records to receive.

Any suggestions how to support "LIMIT 10,20"-like queries in MS SQL ?

Still overloaded with work, maybe add more later.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   C# | SQL
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed