06/18/09
admin
tags:  

Check if method is overridable


For a method or properties to be overridable, it must has a virtual property in its base class set as true as well, is final must be set as true.

To determine whether a method is overridable, it is not sufficient to check that IsVirtual is true. For a method to be overridable, IsVirtual must be true and IsFinal must be false. For example, a method that is non-virtual might implement an interface method.

The common language runtime requires all methods that implement interface members to be marked as virtual; therefore, the compiler marks the method virtual final. Thus there are cases where a method that is marked as virtual is not overridable.

06/17/09
admin
tags:  

How to connect ASP.NET app to use MySQL


A very easy way to connect ASP.NET application to use MySQL database is to use the MySQL Net Connector. With just the following lines of code, you can easily hookup your ASP.NET application to any MySQL db.

  public static string GetConnectionString()
        {

            string connStr = String.Format(”server=hostname;user id=dbname; password=password;database=dbname; pooling=false”, “hostname”, “dbname”, “password”);
                return connStr;
            }

        protected void btnProceed_OnClick(object sender, EventArgs e)
        {
            MySql.Data.MySqlClient.MySqlConnection mycon = new MySqlConnection(GetConnectionString());
            if (mycon.State != ConnectionState.Open)
            {
                try
                {
                    mycon.Open();
                    string strQuery = “select * from table”;
                    MySqlDataAdapter adapter = new MySqlDataAdapter(strQuery, mycon);
                    DataSet myDataSet = new DataSet();
                    adapter.Fill(myDataSet, “mytable”);
                }
                catch (MySqlException ex)
                {
                    throw (ex);
                }
            }

        }

05/28/09
admin

Make Firefox show fonts nicely as Internet Explorers


I found something very interesting to know this morning, that is Firefox’s always shown fonts in web page a little differently than IE browsers. IE tends to show fonts more smooth and nice. There’s actually a way to change the settings so that Firefox could show fonts and lines more nicely like Internet Explorer. To do that,

1. Right click on Desktop and Go Properties
2. Go to Appearance tab, click on Effects
3. Notice the checked line, use the following method to smooth edges of screen fonts, make sure you choose ClearType instead of Standard.

Try again and Firefox now shows fonts nicely as IE!

05/26/09
admin
tags:  

Ajaxify a page with usercontrols using delegate


This post points out how to ajaxify a page, which contains a usercontrol that is updatable by user. Whenever the usercontrol’s controls are updated, we will use Ajax to catch that updates and display at parent page. This is doable and it just requires a delegate to be registered in the usercontrol page.

First, in the usercontrol, we need to:
1. Register a delegate object:

public delegate void userControlChangedHandler(object sender, EventArgs e);

public event userControlChangedHandler userControlChanged;

Then, we also implement a method that will run when subscribers get notified by the delegate.

 protected virtual void updateProperties(object sender, EventArgs e){

//update usercontrol properties…
if (userControlChanged != null)
    userControlChanged(this, e);

}

and in the parent page, all we need to do is put this in page_init

userControl.userControlChanged += new userControlChangedHandler(aParentMethod);


admin
tags:  

Australia safest to be in economy crisis


A very interesting news article today saying that Australia happens to be the safest country in the world throughout the economy downturn. Coming along, China and Singapore ranked 2nd and third space respectively. Wow, that’s pretty impressive.

http://www.news.com.au/business/story/0,27753,25545056-462,00.html

05/24/09
admin
tags:  

Security Exception when running on IIS7


I stumbled upon an error when deploying a web application onto IIS7 running on Vista. After days of trying to solve, it’s actually due to the fact that the application is set to medium trust but it actually needs Full Trust due to using Reflection in the code. There’s not much to do unless the hosting provider allow me to change the trust level but apparently it seems like this is not possible. They’re still trying to find out what they can do…

In the mean time, there’s a good Wiki post here http://www.fbwiki.com/index.php?title=PartialTrustIssue which explains the problem.

Update:

Apparently, it’s because my application is using Data Access Application Block, which requires use of the full trust security level. Applying patch 2554 to the source allows applications to run under partial trust scenarios, for example, in a hosted ASP.NET environment. To solve that, download this:

http://www.codeplex.com/entlib/Release/ProjectReleases.aspx?ReleaseId=1339

05/11/09
admin
tags:  

Compress WebResource.axd in Client side HTML


A very handy tool to compress the annoying webresources.axd script.

http://madskristensen.net/post/Compress-WebResourceaxd-in-ASPNET.aspx

04/28/09
admin
tags:  

Wild Wild Adelaide


Saw some photos showcasting the wild weather of South Australia, for those who are thinking of coming to SA to work.

image001

Read the rest of this entry »

04/26/09
admin
tags:  

Radio Button problems in a repeater item template


When using radio button in a repeater item template, there’s a problem of grouping them to a unique name. Solution can be found:

http://www.developer.com/net/asp/article.php/3623096

04/23/09
admin
tags:  

Regular Expression for validating Australian phone numbers


A very useful regular expression for validation Australian wide phone number, including mobile phones. This would accepts all forms of Australian phone numbers in different formats (area code in brackets, no area code, spaces between 2-3 and 6-7th digits, +61 international dialing code). Checks that area codes are valid (when entered).

^\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$