2009/05/29

Get browser capabilities

I learn from Ramp Up. This is useful if you want to know client support javascript or not.
HttpBrowserCapabilities browser = Request.Browser;
Label1.Text = "Browser Capabilities\n"
  + "Type = " + browser.Type + "\n"
  + "Name = " + browser.Browser + "\n"
  + "Version = " + browser.Version + "\n"
  + "Major Version = " + browser.MajorVersion + "\n"
  + "Minor Version = " + browser.MinorVersion + "\n"
  + "Platform = " + browser.Platform + "\n"
  + "Is Beta = " + browser.Beta + "\n"
  + "Is Crawler = " + browser.Crawler + "\n"
  + "Is AOL = " + browser.AOL + "\n"
  + "Is Win16 = " + browser.Win16 + "\n"
  + "Is Win32 = " + browser.Win32 + "\n"
  + "Supports Frames = " + browser.Frames + "\n"
  + "Supports Tables = " + browser.Tables + "\n"
  + "Supports Cookies = " + browser.Cookies + "\n"
  + "Supports VBScript = " + browser.VBScript + "\n"
  + "Supports JavaScript = " + browser.EcmaScriptVersion.ToString() + "\n"
  + "Supports Java Applets = " + browser.JavaApplets + "\n"
  + "Supports ActiveX Controls = " + browser.ActiveXControls + "\n";
Please replace the "\n" with "<br />".

2009/05/23

Javascript: Get client's TimeZone

How to know client's time and time zone? The simplest way that can do this is using the javascript.
<script type="text/javascript">
function displayTime()
{
var localTime = new Date();
//this one will give you the GMT offset
var timezone = localTime.getTimezoneOffset()/60 * (-1);
var div = document.getElementById("div1");
div.innerText = "GMT" + timezone;
}
</script>
Or simply use
<script type="text/javascript">
function displayTime()
{
var div = document.getElementById("div1");
div.innerText = (new Date()).toString();
}
</script>

2009/05/14

SQL 2005: T-SQL Get table name or Stored Procedure name

How to get all the tables' name?
Select * 
From sysobjects 
Where type = 'U'
Order By name
Change the type to 'P' and you will get all the Stored Procedures.
Change the type to 'F' and you will get all the UDF (User-Defined Function).
More details from here.

Another way to get the tables:
Select *
From sys.tables
How to get the content of stored procedures?
Select text From syscomments Where id = 
(Select id From sysobjects Where type='P' and name = 'SprocName')
or
Exec sp_helptext SprocName
I prefer the second one.

2009/05/13

MultiThread in ASP.Net

How to use multithread in ASP.Net web form? Here is what I did:
private void MethodA(List<string> data)
{
//runing some stuff

//create a new thread to call another method
ThreadPool.SetMaxThreads(5, 5);
ThreadPool.QueueUserWorkItem(new WaitCallback(MethodB), paramsNeededByMethodB);

//keep running your original logic
//.......
}

private void MethodB(object parameters)
{
//cast to the correct data type
List<string> lstData = (List<string>)parameters;

//start your logic from here
//.......
}
Note:
1. MethodB must take the object as a parameter, no other data type is allowed.
2. Don't use too many threads. IIS will manage threads by itself. Here I set the max thread to 5.

[ASP.Net]Set TextBox to ReadOnly

Set TextBox's ReadOnly property to "True" will cause many side effects. How to retain all the functionalities and also have the ReadOnly function turn on? Here is the better way to do this compare with setting the ReadOnly property directly.
TextBox1.Attributes.Add("readonly", "readonly");
Let me know if you have better approach. :)