Saturday, March 28, 2009

Many people using master page might wonder why calendar control is not opening if they are using master page in their normal aspx page., If you add and call the JavaScript cleaner control similar to the normal aspx page calendar won’t be displayed in the page using master page….so I just posting this article to show you how this works….
There is no extra or special coding for this…
First, add JavaScript/CSS reference in MASTER page like below,

Then call the JavaScript function to show the calendar based on the JavaScript you are using. Here my function is
showCalendar(<TextBox Name>,<Date Format>)
instead of passing control name we are passing ID of the control. This is the only change you have to remember…

Monday, March 23, 2009

Add the JavaScript function just below the HTML <title> tag. This function should have __doPostBack to return value.

1: <scriptlanguage="javascript">

2: function RetVal()

3: {

4: var testVar = 'abc'

5: __doPostBack('Test',testVar);

6: }

7: </script>

Add a label to display the values from JavaScript function.
Add a text box to page and set the AutoPostBack property to true. One control with AutoPostBack property set to true is required in the page to get the value from JavaScript function using __doPostBack.
In Page_Load write the following code.

1: protectedvoid Page_Load(object sender, EventArgs e)

2: {

3: if (IsPostBack)

4: {

5: string arg = Request.Form["__EVENTTARGET"];

6: string val = Request.Form["__EVENTARGUMENT"];

7: if (arg == "Test")

8: {

9: Label1.Text = val;

10: }

11: }

12: else

13: {

14: string script;

15: script = @"<SCRIPT language='javascript'> RetVal

();" + "</SCRIPT>";

16: Page.RegisterStartupScript("Test", script);

17: }

18: }

Page.RegisterStartupScript: Allows ASP.NET server controls to emit client-side script blocks in the Page, now this method is obsolete, in ASP.NET 2.0 it gives you an error - or more correctly warnings telling you that both functions are obsolete.'System.Web.UI.Page.IsStartupScriptRegistered(string)' is obsolete: 'The recommended alternative is ClientScript.IsStartupScriptRegistered(string key).
"The __EVENTTARGET hidden variable will tell the server ,which control actually does the server side event firing so that the framework can fire the server side event for that control."
The __ EVENTARGUMENT variable is used to provide additional event information if needed by the application, which can be accessed in the server
Execute the code and see the result…

Tuesday, January 13, 2009

Step1.
To create a new Window Service, pick Windows Service option from your Visual C# Projects, give your service a name, and click OK.
This action will add WinService1.cs class to your project.
Set your ServiceName to your own name so it would be easier to recognize your service during testing OR you can set this property programmatically using this line this.ServiceName = "MyWinService";Step 2. Add functionality to your service
The default code of WebService1.cs added will have two overridden functions OnStart and OnStop. The OnStart function executes when you start your service and the OnStop function gets execute when you stop a service. I write some text to a text file when you start and stop the service.

Step 2.5.
a) Return to Design view for WinService1.
b) Click the background of the designer to select the service itself, rather than any of its contents.
c) Right click on the Designed Windows and in the Properties window, click the Add Installer link in the gray area beneath the list of properties.
d) By default, a component class containing two installers is added to your project. The component is named ProjectInstaller, and the installers it contains are the installer for your service and the installer for the service's associated process.
e) Access Design view for ProjectInstaller, and click ServiceInstaller1. In the Properties window, set the ServiceName property to MyNewService. Set the StartType property to Automatic.
f) In the designer, select ServiceProcessInstaller1 (for a Visual Basic project), or serviceProcessInstaller1 (for a Visual C# project). Set the Account property to LocalService. This will cause the service to be installed and to run on a local service account.
After the above procedure, try registering using InstallUtil utilities.

Step 3: Install and Run the ServiceBuild of this application makes one exe, MyWinService.exe. You need to call installutil to
egister this service from command line.
installutil C:\mcWebService\bin\Debug\mcWebService.exe
You use /u option to uninstall the service.
installutil /u C:\mcWebService\bin\Debug\mcWebService.exe
Run the application

Step 4: Start and Stop the Service
You need to go to the Computer Management to start and stop the service. You can use Manage menu item by right clicking on My Computer.
Under Services and Applications, you will see the service MyWinService. Start and Stop menu item starts and stops the service.
Go to your temp directory and see if text file is there with contents or not.
That's it.

Both delegates and interfaces allow a class designer to separate type declarations and implementation. A given interface can be inherited and implemented by any class or struct; a delegate can created for a method on any class, as long as the method fits the method signature for the delegate. An interface reference or a delegate can be used by an object with no knowledge of the class that implements the interface or delegate method. Given these similarities, when should a class designer use a delegate and when should they use an interface? Use a delegate when: • An eventing design pattern is used. • It is desirable to encapsulate a static method. • The caller has no need access other properties, methods, or interfaces on the object implementing the method. • Easy composition is desired. • A class may need more than one implementation of the method. Use an interface when: • There are a group of related methods that may be called. • A class only needs one implementation of the method. • The class using the interface will want to cast that interface to other interface or class types. • The method being implemented is linked to the type or identity of the class: for example, comparison methods. One good example of using a single-method interface instead of a delegate is IComparable or IComparable. IComparable declares the CompareTo method, which returns an integer specifying a less than, equal to, or greater than relationship between two objects of the same type. IComparable can be used as the basis of a sort algorithm, and while using a delegate comparison method as the basis of a sort algorithm would be valid, it is not ideal. Because the ability to compare belongs to the class, and the comparison algorithm doesn’t change at run-time, a single-method interface is ideal.

Thursday, January 8, 2009

Advantages of Using Globally Unique Identifier (GUID) as a Primary Key Advantages:
■ If you use an auto-number Id column and if many people are creating new DataRow objects, it will be difficult for you to merge data later because there may be many duplicate keys.

■ The Guid data type is a “surrogate” key, meaning that its only purpose is to define uniqueness of the row and aid in connecting multiple tables together via relationships. This means that there is no reason for a user to see and change this value, which simplifies maintenance of the DataSet. If you allow the user to change the primary key on a row, you have to propogate the change down to all of the related tables. For example, changing the CompanyId value requires the update of the Company Id value in the Employee table.

■ The use of the Guid can simplify the joining of tables, which is better than the scenarios where you use compound keys that are based on the actual data. Compound keys typically result in smaller data footprints because the key is based on actual data, whereas joining tables is usually more difficult because compound joins are required. Remember that if you are using compound keys that are based on the actual data, you inevitably need to deal with recursive updates.

The first thing that most Javascript programmers end up doing is adding some code to their program, similar to this:
window.onload = function(){ alert("welcome"); }
Inside of which is the code that you want to run right when the page is loaded. Problematically, however, the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using “window.onload” in the first place is due to the fact that the HTML 'document' isn't finished loading yet, when you first try to run your code.
To circumvent both problems, here comes jQuery...Write Less, Do More, JavaScript Library.