More pseudo-registers

April 30th, 2008

There is another pseudo-register useful when working with C# language:

$exception

It contains last exception that is thrown by an application.
Suppose that we have code like this:

C#:
try
{
    // something
}
catch
{
    // do something else
}

with $exception pseudo-register you can easily examine it:

exception

Pseudo-registers in VS debugger

April 12th, 2008

I found a very interesting feature of Visual Studio's debugger. It's been there for a long time but many developers do not know (including me) that pseudo-registers can be helpful.
There are more registers but I will mention just two of them.

@ERR

Well, it returns the same as GetLastError(), It optionally can return formatted string - just write it like @err,hr
I think I don't need to add more, screens below are self-explanatory

Code
Watch window

$user

Provides many informations about a user executing current process

Watch window - user

Happy debugging.

Did you know - C#

April 12th, 2008

Did you know where the C# name come from? I didn't :D
According to wikipedia: "The name "C sharp" was inspired from musical notation where a sharp indicates that the written note should be made a half-step higher in pitch".

Stupid :D

Hell Helper

February 19th, 2008

I have written another tiny tool which helps me in every-day work.
Look at the projects page.

Postback from javascript - the right way

January 31st, 2008

Sometimes a programmer must do very weird things in his ASP.NET webapp. Among them, there is a postback initiated in custom javascript. Before .NET Framework 2.0, it was no good solution to achieve it. Fortunately it can be done without much effort nowadays.

There is an interface called IPostBackEventHandler which must be implemented by a page or a control. Then you must create javascript containing reference to postback function retrieved by ClientScriptManager.GetPostBackEventReference(...) method.

The sample web control's codebehind can look like below:

C#:
public class MyControl : Control, IPostBackEventHandler
{
    // this method will be called on postback initiated in javascript
    public void RaisePostBackEvent(string eventArgument)
    {
        if (eventArgument == "foo")
        {
            // do something
        }
    }
}

then we create javascript in aspx / ascx file:

ASP:
<script>
function Test()
{
    <%= Page.ClientScript.GetPostBackEventReference(this, "foo"); %>
}
</script>

Now, when a Test() function is called in a browser, our page will do a nice, clean postback :)

Designed by SirMike © All rights reserved

Valid XHTML 1.0! Valid CSS!