Tuesday, December 30, 2008
Tip: CalendarExtender In Update Panel with ReadOnly TextBox
Saturday, December 6, 2008
Tips: How to compress JSON response using GZIP
I have been involving in a ASP.NET web project that makes heavy use of JSON technique and Ajax concepts. The web pools for new data from a Windows 2003 web server every 30 seconds. The size of the data can vary from 100KB to 1MB. This poses performance issue for customers that have slow Internet connection.
IIS6 provides the capability to Gzip the web content before sending to the clients. Figure 1 and Figure 2 show the typical setting that i uses in order to compress JSON and Ajax response.
Saturday, October 4, 2008
Tips: Anonymous access gets error 401.1 every time the Domain Controller pushes the domain policy to the web server.
The reason why i received the error 401.1 overnight after i had done an IISRESET to the web server was because of my domain controller was refreshing the web server group policy at a certain time. The refresh happened to remove the IUSR_SERVER anonymous account from the group policy, threfore any anonynmou account trying to browse the web site would get the 401.1 error. If i run the IISRESET again, the group policy will be reset to the web server's original configuration, thus allowing anonymous users to browse the web site.
The solution to the problem is to edit the Domain Controller Domain Policy. Edit the "Access this computer from the network" policy under the "Local Policies-->User Rights Assignment" section and add in the IUSR_SERVER account into the policy. The next time the DC refreshes the web server policy, the IUSR_SERVER is included in the web server policy also. THe picture below shows the actual setup panel.
Saturday, September 13, 2008
Tips: Regular Expressions for validating currency
_en_US = /(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/;
_ms_MY = /^(?=\d)(?:(?!(?:(?:0?[5-9]|1[0-4])(?:\.|-|\/)10(?:\.|-|\/)(?:1582))|(?:(?:0?[3-9]|1[0-3])(?:\.|-|\/)0?9(?:\.|-|\/)(?:1752)))(31(?!(?:\.|-|\/)(?:0?[2469]|11))|30(?!(?:\.|-|\/)0?2)|(?:29(?:(?!(?:\.|-|\/)0?2(?:\.|-|\/))|(?=\D0?2\D(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|2[0-8]|1\d|0?[1-9])([-.\/])(1[012]|(?:0?[1-9]))\2((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?:$|(?=\x20\d)\x20)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/;
_zh_CN = /^(?=\d)(?:(?!(?:1582(?:\.|-|\/)10(?:\.|-|\/)(?:0?[5-9]|1[0-4]))|(?:1752(?:\.|-|\/)0?9(?:\.|-|\/)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\.|-|\/)(?:29|30))))(\d{4})([-\/.])(0?\d|1[012])\2((?!00)[012]?\d|3[01])(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/;
_zh_HK = /^(?=\d)(?:(?!(?:1582(?:\.|-|\/)10(?:\.|-|\/)(?:0?[5-9]|1[0-4]))|(?:1752(?:\.|-|\/)0?9(?:\.|-|\/)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\.|-|\/)(?:29|30))))(\d{4})([-\/.])(0?\d|1[012])\2((?!00)[012]?\d|3[01])(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/;
Thursday, July 3, 2008
Tips: Session is lost when using showModalDialog.
Monday, June 23, 2008
Tips: How to create an animation using the MS AjaxToolkit's JavaScript
<asp:ScriptManager ID="ScriptManager1" runat="server" LoadScriptsBeforeUI="false">
<Scripts>
<asp:ScriptReference Assembly="AjaxControlToolkit" Name="AjaxControlToolkit.Common.Common.js" />
<asp:ScriptReference Assembly="AjaxControlToolkit" Name="AjaxControlToolkit.Compat.Timer.Timer.js" />
<asp:ScriptReference Assembly="AjaxControlToolkit" Name="AjaxControlToolkit.Animation.Animations.js" />
</Scripts>
</asp:ScriptManager>
Add the following JavaScript codes into your aspx page.
<script type="text/javascript">
//Get a handle to the animation Target. The target can be anything like a 'div', 'table', etc
var target = $get("animationTarget");
//Create an instance of the FadeAnimation .
var fadeAnimation = new AjaxControlToolkit.Animation.FadeInAnimation();
//Set the Duration
fadeAnimation.set_duration( 1.0 );
//Set the Animation Target as a Sys.UI.Control object
fadeAnimation.set_target( target );
//Set the Maximum Opacity Value
fadeAnimation.setValue( 50 );
//Play the Animation
fadeAnimation.play();
</script>
Monday, June 9, 2008
My ISP TM Streamyx Sucks
http://forum.lowyat.net/topic/715267
Sunday, May 18, 2008
Tip: How to solve "__pendingCallbacks[...].async is null or not an object"?
function WebForm_CallbackComplete() {
for (var i = 0; i < __pendingCallbacks.length; i++) {
callbackObject = __pendingCallbacks[i];
if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest.readyState == 4)) {
WebForm_ExecuteCallback(callbackObject);
if (!__pendingCallbacks[i].async) {
__synchronousCallBackIndex = -1;
}
__pendingCallbacks[i] = null;
var callbackFrameID = "__CALLBACKFRAME" + i;
var xmlRequestFrame = document.getElementById(callbackFrameID);
if (xmlRequestFrame) {
xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);
}
}
}
}
Saturday, April 19, 2008
ASP NET: How to secure a web page in a sub directory using role for your web site?
1 <location path="MemberDirectory">
2 <system.web>
3 <authorization>
4 <allow roles="MEMBER" />
5 </authorization>
6 </system.web>
7 </location>
But to control the role that can access a specific file in a sub-directory within our site requires us to set it differently. The following example shows how it can be done:
1 <location path="Admin/UserManagement">
2 <system.web>
3 <authorization>
4 <deny users="*" />
5 </authorization>
6 </system.web>
7 </location>
8
9 <location path="Admin/UserManagement/users.aspx">
10 <system.web>
11 <authorization>
12 <allow roles="ADMIN" />
13 <deny users="*" />
14 </authorization>
15 </system.web>
16 </location>
The 1st line shows the setting to deny all users to access the particular sub-directory.
The 9th line shows the setting to allow access to individual web page for the ADMIN role.
In order for any page in the UserManagement sub-directory to be shown in a MS ASP web menu, you need to include all the individual pages in the setting.
Sunday, March 23, 2008
ASP.NET: Object Reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] System.Web.Hosting.ISAPIWorkerRequestInProc.GetServerVariable(String name) +1618 System.Web.Security.WindowsAuthenticationModule.OnEnter(Object source, EventArgs eventArgs) +593 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
Wednesday, February 20, 2008
Tip: Securing ASP pages in menu.
1. Add a new Web.config file into the directory that you want to control access. For example, I
put a config file into the Admin folder.
2. Modify the Web.config file to include the following statements:
1 <?xml version="1.0"?>
2 <configuration>
3 <system.web>
4 <authorization>
5 <allow roles="Administrator"/>
6 <deny users="*"/>
7 </authorization>
8 </system.web>
9 </configuration>
3. In the Web.siteMap file, add the following line. By adding "Administrator" as the roles for that particular web page, an admin login will display the "Admin Page" but not the "Game Page".
1 <?xml version="1.0" encoding="utf-8" ?>
2 <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
3 <siteMapNode url="default.aspx" title="Home" description="" roles="Administrator, Agent">
4 <siteMapNode url="~/Admin/test1.aspx" title="Admin Page" description="" roles="Administrator"/>
5 <siteMapNode url="~/Game/test2.aspx" title="Game Page" description="" roles="Agent"/>
6 </siteMapNode>
7 </siteMap>
Thursday, January 31, 2008
Tip: How to enable post back from a custom web control?
public classs MyControl: WebControl, IPostBackEventHandler
{
........
protected override void OnInit(EventArgs e)
{
PostBackOptions options = new PostBackOptions(this);
options.ClientSubmit = true;
Page.ClientScript.GetPostBackEventReference(options);
}
}
This enables the implementation of the following user functions:
1. Pass back key press from user computer back to server.
2. Any scenarios that require __doPostBack to be called manually in code.
Tuesday, January 29, 2008
Tip: Embed an Autocomplete Ajax Control into a Web Control
1. Place the Ajax control instance after the base.OnPreRender() function. The reason
is that Ajax control needs to get an instance of the Target Control when it's
created.
Tip: Closing an IE Modal Dialog
//To show the modal dialog.
function DisplayMenu()
{
var url = "page.aspx";
var winName = "ProblemReportActions";
var height = 280;
var width = 500;
var returnedValue = '';
var params = '';
var returnedValue = ShowModalWindow( url, winName, width, height,params);
if(returnValue != null)
{
postBack(returnValue); //Javascript Post Back for the main window
}
}
//In the C# aspx page add the onclick attributes to the button to close the dialog.
//the first button actualy close the dialog and returns something to the main window.
//the second button basically closes the dialog like a cancel button.
this.bt_ok.Attributes.Add("onclick", "closeDialog('" + this.txtOption.UniqueID + "');return false;");
this.bt_cancel.Attributes.Add("onclick", "window.close();return false;");