2008/11/07

Dynamically enable/disable ASP.Net AJAX controls

The ASP.Net AJAX Toolkit is a good stuff because it can let you achieve some very cool functions without doing too much hard works. However, how to do it if I want the AJAX control works only in some conditions? For example, I want to have the same function like this one. After many times try and error, I finally figure out the correct procedures. Here are the steps:

Tips: Storing data in the web.config file

You can store any string you want.
<appSettings>
  <add key="SSRS" value="http://localhost/Reports/Pages/Report.aspx" />
  <add key="FTPServer" value="ftp.myftp.com" />
</appSettings>
Here is how to use:
string strSSRS = ConfigurationManager.AppSettings["SSRS"];

2008/11/04

Encode Query String by using Base64 (6/24/2009 updated)

Recently, I read a post about encrypting the Query String, and it's quite interested. You can read it here. However, we can use a simpler way to do the same thing like this:
public static string EncryptString(string toEncode)
{
  try
  {
    byte[] toEncodeAsBytes = Encoding.UTF8.GetBytes(toEncode);
    return Convert.ToBase64String(toEncodeAsBytes);
  }
  catch (Exception ex)
  {
    //do your error handling here
  }
}

public static string DecryptString(string toDecrypt)
{
  try
  {
    byte[] encodedDataAsBytes = Convert.FromBase64String(toDecrypt.Replace(" ", "+"));
    return Encoding.UTF8.GetString(encodedDataAsBytes);
  }
  catch (Exception ex)
  {
    //do your error handling here
  }
}

You can apply some other encryption algorithms like TripleDES before applying the Base64 encoding.

PS: Be careful of the URL length restriction.