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#:
  1. public class MyControl : Control, IPostBackEventHandler
  2. {
  3.     // this method will be called on postback initiated in javascript
  4.     public void RaisePostBackEvent(string eventArgument)
  5.     {
  6.         if (eventArgument == "foo")
  7.         {
  8.             // do something
  9.         }
  10.     }
  11. }

then we create javascript in aspx / ascx file:

ASP:
  1. <script>
  2. function Test()
  3. {
  4.     <%= Page.ClientScript.GetPostBackEventReference(this, "foo"); %>
  5. }
  6. </script>

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

Quick Assembly Info

January 28th, 2008

Today I added another tiny application to my project list - click for Quick Assembly Info

MS 70-536 passed

January 27th, 2008

I have passed my first MS exam :) Although it covers many aspects of .NET, it is the most stupid exam I have ever taken (Econometrics which I passed on a 6th attempt does not count :D )
Questions are very confusing and when you do not memorize most of .NET classes and methods you will probably fail. Many possible answers differ only by method signatures and you need to know exactly when the parameter A must be on position 1 and the parameter B must be on position 2. I am a little bit disappointed because there were no questions about designing and solving problems. IMHO this kind of exam does not prove that a programmer has any useful skills.

Anyway, I'm glad I could make it :)

Gaming

January 21st, 2008
The Witcher...
    Company of Heroes: Opposing Fronts...
        Test Drive Unlimited...

            I won't be here for next few weeks ;)

AirFramework – short video

January 8th, 2008

I would like to show you my simple, portable OpenGL framework in action. I work on it in my spare time. It's nothing special but it is not developed to write a computer game. It mainly helps me learning how to create various 3D effects using shaders. I decided not to write an engine or something which is very trendy (I hate that word) - just a simple framework which is able to render models in my own format, render textures available in memory, change render states and write text. Also an interactive console which can change many internal options and print debug information.

Below there is a simple, diffuse lighting model computed per fragment.

Here are two screenshots presenting difference between vertex and fragment computations:

Interactive console and wireframed rendering:

Rendering text and textures from memory:

Sorry for the poor quality of the movie but it's youtube only :D

No source code or binaries, I'm sorry. The code isn't tested well and in fact shaders look lame (I created them in a hurry) - please, forgive me this time ;)

Designed by SirMike © All rights reserved

Valid XHTML 1.0! Valid CSS!

Powered by Rootnode