Archive for March, 2011

Using iMacro for Performance Testing

Stopwatch is useful for counting the duration of the steps.

No Comments

jQuery UI Dialog with AJAX Content

<script type="text/javascript">
    $(function ()    {
            modal: true,
            open: function ()
            height: 400,
            width: 400,
            title: 'Dynamically Loaded Page'

, ,

No Comments

Writing a Custom Membership Provider for the Login Control in ASP.NET 2.0

1. Create a Class inheriting MembershipProvider

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Data;
using System.Data.Common;

namespace myHelper
    public class As400MembershipProvider : MembershipProvider
	public override bool ValidateUser(string username, string password)
	     Boolean isAuthenicated = false;
             //Validate logic here
             return isAuthenicated ;

2. Install the MembershipProvider in web.config


Microsoft Guide Line:
Implementing a Membership Provider
Implementing a Role Provider

No Comments

Crystal Reports 13 JavaScript Error in Visual Studio

First, locate “crv.js” file in “C:\Windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETClientFiles\crystalreportviewers13\js\crviewer”, then search for this code block at the bottom of the file

if(typeof(Sys)!=='undefined') {

And replace it with this code block

if(typeof(Sys.Application)!=='undefined') {

After changed this code, everything works fine now and reports shows in ASP.NET pages.

No Comments

Crystal Reports for Visual Studio 2010 Production Release Now Available

No Comments

Using RequiredFieldValidator to Validate User Control

1. Add [ValidationProperty] tag to define the value to be validated

public partial class LocationInputUserControl : System.Web.UI.UserControl
	public string Location
			return LocationTextBox.Text.Trim().ToUpper();

2. the ControlToValidate=”” property of validation control on the page should be the ID of the user control, colon(:), then the ID of the control to which ‘value’ is associated.

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="LocationInputUserControl1:LocationTextBox"
	runat="server" ErrorMessage="<%$ Resources:ErrorMessage, PleaseEnterLocation %>"
	Text="*" CssClass="errMessage"></asp:RequiredFieldValidator>

No Comments

Executes a shell command synchronously

/// <summary>
/// Executes a shell command synchronously.
/// </summary>
/// <param name="command">string command</param>
/// <returns>string, as output of the command.</returns>
public void ExecuteCommandSync(string command)
		// create the ProcessStartInfo using "cmd" as the program to be run,
		// and "/c " as the parameters.
		// Incidentally, /c tells cmd that we want it to execute the command that follows,
		// and then exit.
		string cmdPath = System.IO.Path.Combine(Environment.SystemDirectory, "cmd.exe");
		System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(cmdPath, "/c" + command);

		Console.WriteLine("Executing Command: " + command);

		// The following commands are needed to redirect the standard output.
		// This means that it will be redirected to the Process.StandardOutput StreamReader.
		procStartInfo.RedirectStandardOutput = true;
		procStartInfo.UseShellExecute = false;

		// Do not create the black window.
		procStartInfo.CreateNoWindow = true;

		// Now we create a process, assign its ProcessStartInfo and start it
		System.Diagnostics.Process proc = new System.Diagnostics.Process();
		proc.StartInfo = procStartInfo;

		// Get the output into a string
		string result = proc.StandardOutput.ReadToEnd();

		// Display the command output.
	catch (Exception objException)
		// Log the exception

No Comments

WerFault.exe Causing 100% CPU Loading

To disable the Windows Error Reporting Service (WerSvc) using control

1. Open control panel.
2. Select “System & Maintenance”
3. Select “Administrative Tools”
4. Select “Services”
5. Right-Click “Windows Error Reporting Service”
6. Select “Properties”
7. In the “Service Status” Section Click [Stop]
8. Set “Startup type:” to “Manual” or if this is started by another
application select “Disabled”
9. Save and close the dialog boxes.

CPU utilisation returned to normal immediately.

No Comments

Using Web Services with a Site Protected by Forms Authentication

1. Start Visual Studio, and create a Windows Application project.

2. Add a button and text box to Form1.

3. Change the text box properties so that Multiline is True and Scrollbars is Vertical.

4. Resize the text box to fill the form under the button.

5. Add a Web reference to the Authentication Web service in the site that is protected by forms authentication; the Authentication Web service can be found in the path http://siteCollectionName/_vti_bin/authentication.asmx. Name this Web reference fbaAuth.

6. Add a second Web reference to the Lists Web service; it can be found in the path http://siteCollectionName/_vti_bin/lists.asmx. Name this Web reference fbaLists.

7. On the form, double-click Button1 to switch to code view and create an event handler for the click event. Create two variables for the Web service proxies, as shown in the following code.

fbaAuth.Authentication auth = new fbaAuth.Authentication();
fbaLists.Lists lists = new fbaLists.Lists();

8. Create a CookieContainer collection object for the Authentication class proxy; the authentication cookie will be stored in this container after calling the Login method.

9. Call the Login method, and check the result from that call, as shown in the following code.

auth.CookieContainer = new System.Net.CookieContainer();
auth.AllowAutoRedirect = true;
fbaAuth.LoginResult lr = auth.Login("myUserName", "myUserPassword");

if (lr.ErrorCode == fbaAuth.LoginErrorCode.NoError)
  //Now we can talk to the Lists Web service.

If the Login method succeeds, the proxy for the Authentication Web service has a valid authentication cookie in its CookieContainer collection. To reuse this cookie, just set the CookieContainer property for the Lists Web service proxy equal to the CookieContainer property of the Authentication Web service proxy. You can then make calls to the Lists Web service, and the authentication cookie will be used to authenticate and authorize the request. That means that when you make a Web service request, the cookie with authenticate and authorize the request based on the permissions of whatever account was used to create the authentication cookie.

Following is the remainder of the code sample.

if (lr.ErrorCode == fbaAuth.LoginErrorCode.NoError)
   // Now we can talk to the Lists Web service.
   lists.CookieContainer = auth.CookieContainer;
   XmlNode xData = lists.GetListCollection();


No Comments

Paging in ListView

1. Place the DataPager OUTSIDE the ListView
* Define PagedControlID to the ListView and the PageSize

<asp:DataPager ID="DataPager1" PagedControlID="ResultListView" PageSize="10" runat="server"
	<asp:NextPreviousPagerField FirstPageText="&lt;&lt;" ShowFirstPageButton="True" ShowNextPageButton="False"
		ShowPreviousPageButton="False" />
	<asp:NumericPagerField />
	<asp:NextPreviousPagerField LastPageText="&gt;&gt;" ShowLastPageButton="True" ShowNextPageButton="False"
		ShowPreviousPageButton="False" />

2. Load the Data and Save it in ViewState, e.g.

ResultListView.DataSource = ResultDataSet;
ViewState["ResultSet"] = ResultDataSet;

3. Get the result set from the ViewState, and Bind again
* This make the Pager works!!!

protected void DataPager1_PreRender(object sender, EventArgs e)
	ResultListView.DataSource = ViewState["ResultSet"];

No Comments