December 22, 2008

Nullable Types in C#

0 comments

int x = 0; //valid statement
int y = null; //compile time error

This is because we know that null is a value for reference types and since int is a value type it cannot hold the value null in it. So if there comes a situation where u need to hold null value inside an int then the solution is the Nullable Type.

Any Value Type can be Nullable Type, which means that the default value can hold the possible value in its data range as well as a new value 'null' in it. The syntax for this is,

int? x = null; //valid statement; now x is a nullable type

Also dont guess that since now x can hold null value, it can be reference type. This is wrong. What Nullable Type is like a wrapper around a value type which can hold a null value also. So the value of x is stored in stack(by default).

December 18, 2008

CodeBehind Files in asp.net

0 comments

Hey Friends, check the following links to get an indepth understanding of code-behind classes for aspx pages. 

Before going to these links check ur self that in VS2008, for a website u will find CodeFile attribute in the page directive, whereas for a web application u will find CodeBehind attribute in the page directive.


December 03, 2008

Enable IE6 Toolbar

0 comments

I had the same problem with the IE toolbar (IE7 under win 2003, using it to style a Sharepoint site). A combination of the suggested solutions did the trick:


  • Tools->Internet options->Security Tab->Local Intranet->Custom Level->Run ActiveX Control or PlugIn (Administrator Mode)
  • Tools->Internet Options->Programs->Manage add-ons->IEDeveloperToolbarBHO->Enable
  • Tools->Internet Options->Advanced->Enable third party browser-extensions (requires restart)

November 07, 2008

call a WebService from Browser(javascript code)

0 comments

Following links are helpful for making a webservice request


  • http://debasishpramanik.wordpress.com/2007/08/17/calling-web-service-using-xmlhttp-object/#comment-1021


For getting Basics:

  • http://www.codeproject.com/KB/aspnet/XmlHttpWS.aspx
  • http://www.howtocreate.co.uk/tutorials/javascript/domstructure

November 03, 2008

Creating a Simple User Control

0 comments

User controls allow you to save a part of an existing ASP.NET page and reuse it in many other ASP.NET pages. A user control is almost identical to a normal .aspx page, with two differences: the user control has the .ascx extension rather than .aspx, and it may not have

<HTML>, <Body>, or <Form> tags.


The simplest user control is one that displays HTML only(.ascx file)

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="MyUserControl.WebUserControl1" %>







CopyRight 2008 Ramp Infotech, Inc.
Support at http://www.rampgroup.com


To see it work add this in the .aspx file as:
<%@ Register tagprefix="ramp" TagName="CopyRight" src="CopyRight.ascx" %>


This registers the control with our page and we can use it like






What is there in _VIEWSTATE field?

0 comments

First of all _VIEWSTATE is a field(HTML Element) and its different from what we think about a ViewState.

Now, Will you have a value stored in the _VIEWSTATE field if it is a blank ASP.NET Page or ViewState completely diabled. The answer is yes. If we see the viewsource of this blank page we can find a small serialized value. The reason is the page itself saves approximately 20 bytes of information into the _VIEWSTATE field, which it uses to distribute postback data and viewstate values to the correct controls upon postback.


    The data stored in the _VIEWSTATE field consists of the following
  • Data stored by developers using the Viewstate[""] indexer.
  • Programmatic changes to the control state.

OK, so let us assume that we have a web page with only a Label control on it. Now, let us say that at design time, if we set the “Text” property of the Label to “statictext”. Now, load the page and open the View Source page. We can see the __VIEWSTATE field. Do you think “statictext” is saved there? The answer is, for sure, not. Recall that static properties of controls are assigned at the generated class. So, when the page is requested, the values stored in the generated class are displayed. As such, static properties that are set at design time are never stored in the __VIEWSTATE field. However, they are stored in the generated compiled class, and thus they show up when rendering the page.

Now if we change the label "Text" property to "dynamicText" in the page load then this "dynamicText" is saved in the _VIEWSTATE field. The reason is we have changed the label's "Text" property at run-time and this is done at the page load time during which the tracking of viewstate is enabled(TrackViewState() is enabled in the InitComplete event), the "Text" property is marked as "Dirty" and thus the "SaveViewState" will save the controls new value in the _VIEWSTATE field!

Keep Smiling and Programming!!

November 01, 2008

ViewState - Dynamic Controls

0 comments

The first fact that you should know about dynamic controls is that they should be added to the page at each and every page execution. Never wrap the code that initializes and adds the dynamic control to the page inside a “!IsPostback” condition. The reason is that since the control is dynamic, it is not included in the compiled class generated for the page. So, the control should be added at every page execution for it to be available in the final control tree. The second fact is that dynamic controls play “catch-up” with the page life cycle once they are added. Say, you did the following:

Label lbl = new Label();
Page.Controls.Add(lbl);

Once the control is added to the “Controls” collection, it plays “catch-up” with the page life cycle, and all the events that it missed are fired. This leads to a very important conclusion: you can add dynamic controls at any time during the page life cycle until the “PreRender” event. Even when you add the dynamic control in the “PreRender” event, once the control is added to the “Controls” collection, the “Init”, “LoadViewState”, “LoadPostbackdata”, “Load”, and “SaveViewstate” are fired for this control. This is called “catch-up”. Note though that it is recommended that you add your dynamic controls during the “PreInit” or “Init” events. This is because it is best to add controls to the control tree before tracking of the Viewstate of other controls is enabled…

Finally, what is the best practice for adding dynamic controls regarding Viewstate? Let us say that you want to add a Label at runtime and assign a value to its “Text” property. What is the best practice to do so? If you are thinking the below, then you are mistaken:

Label lbl = new Label();
Page.Controls.Add(lbl);
lbl.Text = "bad idea";

You are mistaken because using the above technique you are actually storing the value of the “Text” property in the Vewstate. Why? Because, recall that once a dynamic control is added to the “Controls” collection, a “catch-up” happens and the tracking for the Viewstate starts. So, setting the value of the “Text” property will cause the value to be stored in the Viewstate.

However, if you do the below, then you are thinking the right way, because you are setting the “Text” property before adding the control to the “Controls” collection. In this case, the value of the “Text” property is added with the control to the control tree and not persisted in Viewstate.

Label lbl = new Label();
lbl.Text = "good idea";
Page.Controls.Add(lbl);

Reducing ViewState - Disabling ViewState

0 comments

Disabling Viewstate would obviously reduce Viewstate size; but, it surely kills the functionality along the way. So, a little more planning is required…

Consider the case where you have a page with a drop down list that should display the countries of the world. On the “Page_Load” event handler, you bind the drop down list to a data source that contains the countries of the world; the code that does the binding is wrapped inside a “!IsPostback” condition. Finally, on the page, you have a button that when clicked should read the selected country from the drop down list. With the setup described above, you will end up with a large __VIEWSTATE field. This is due to the fact that data bound controls (like the drop down list) store their state inside the Viewstate. You want to reduce Viewstate; what options do you have?


  1. Option 1: Simply disable the Viewstate on the drop down list
  2. Option 2: Disable the Viewstate on the drop down list, and remove the “!IsPostback” condition
  3. Option 3: Disable the Viewstate on the drop down list, and move the binding code without the “!IsPostback” condition to the “OnInit” or “OnPreInit” event handlers

If you implement Option 1, you will reduce the Viewstate alright, but with it, you will also lose the list of countries on the first postback of the page. When the page first loads, the code in the “Page_Load” event handler is executed and the list of countries is bound to the list. However, because Viewstate is disabled on the list, this change of state is not saved during the “SaveViewState” event. When the button on the page is clicked causing a postback, since the binding code is wrapped inside a “!IsPostback” condition, the “LoadViewState” event has nothing saved from the previous page visit and the drop down list is empty. If you implement Option 2, you will reduce the Viewstate size and you will not lose the list of countries on postback. However, another problem arises: because the binding code is now executed at each “Page_Load”, the postback data is lost upon postback, and every time, the first item of the list will be selected. This is true because in the page life cycle, the “LoadPostbackdata” event occurs before the “Load” event. Option 3 is the correct option. In this option, you have done the following:

  • Disabled Viewstate on the drop down list
  • Removed the “!IsPostback” condition from the binding code
  • Moved the binding code to the “OnInit” event handler (or the “OnPreInit” event handler)

Since the “Init” event occurs before the “LoadPostbackdata” in the page life cycle, the postback data is preserved upon postbacks, and the selected item from the list is correctly preserved.

Now, remember that in Option 3, you have successfully reduced the Viewstate size and kept the functionality working; but, this actually comes at the cost of rebinding the drop down list at each postback. The performance hit of revisiting the data source at each postback is nothing when compared with the performance boost gained from saving a huge amount of bytes being rendered at the client’s __VIEWSTATE field. This is especially true with the fact that most clients are connected to the Internet via low speed dial up connections.

ASP.NET Page Life Cycle Demonstration

0 comments

Let us take an example ASP.NET page with the following characteristics:


  • It contains a single Label control (lbl) with its “Text” property set to “statictext”
  • It contains a Button control (btnA) with code in its event handler that sets the “Text” property of “lbl” to “dynamictext”
  • It contains a Button control (btnB) whose purpose is to cause a page postback

Now, let us examine what will happen during the page life cycle.

  1. The page is first loaded

    1. The compiled class of the page is generated and “statictext” is assigned to “lbl.Text”
    2. Tracking for Viewstate is enabled in the “InitComplete” event
    3. “LoadViewState” is not fired because there is no postback
    4. “SaveViewstate” is fired, but nothing happens because no change of state is recorded
    5. The page is rendered with the value “statictext” inside “lbl”

  2. btnA is clicked

    1. The previously generated compiled class is handed the request; “lbl.Text” is set to “statictext”
    2. Tracking for Viewstate is enabled
    3. “LoadViewState” is fired, but nothing happens because no change of state was recorded in the previous page visit
    4. “RaisePostbackEvent” event is executed and “btnA” click event handler is fired; “lbl.Text” is set to “dynamictext”; since tracking is enabled at this stage, this item is tracked (marked as “Dirty”).
    5. “SaveViewState” is fired; “dynamictext” is serialized and stored in the __VIEWSTATE field
    6. The page is rendered with the value “dynamictext” inside “lbl”

  3. btnB is clicked

    1. The previously generated compiled class is handed the request; “lbl.Text” is set to “statictext”
    2. Tracking for Viewstate is enabled
    3. “LoadViewState” is fired; since a change of state was recorded from the previous page visit, __VIEWSTATE is loaded and the value “dynamictext” is extracted; this value is then assigned to “lbl”
    4. “RaisePostbackEvent” event is executed; nothing happens here because “btnB” has no event handler for its “Click” event
    5. “SaveViewState” is fired, but nothing happens because no change of state is recorded
    6. The page is rendered with the value “dynamictext” inside “lbl”

What is an Application Pool?

0 comments

When you run IIS 6.0 in worker process isolation mode, you can separate different Web applications and Web sites into groups known as application pools. An application pool is a group of one or more URLs that are served by a worker process or set of worker processes. Any Web directory or virtual directory can be assigned to an application pool.

Every application within an application pool shares the same worker process. Because each worker process operates as a separate instance of the worker process executable, W3wp.exe, the worker process that services one application pool is separated from the worker process that services another. Each separate worker process provides a process boundary so that when an application is assigned to one application pool, problems in other application pools do not affect the application. This ensures that if a worker process fails, it does not affect the applications running in other application pools.

Use multiple application pools when you want to help ensure that applications and Web sites are confidential and secure. For example, an enterprise organization might place its human resources Web site and its finance Web site on the same server, but in different application pools. Likewise, an ISP that hosts Web sites and applications for competing companies might run each companys Web services on the same server, but in different application pools. Using different application pools to isolate applications helps prevent one customer from accessing, changing, or using confidential information from another customers site.

In HTTP.sys, an application pool is represented by a request queue, from which the user-mode worker processes that service an application pool collect the requests. Each pool can manage requests for one or more unique Web applications, which you assign to the application pool based on their URLs. Application pools, then, are essentially worker process configurations that service groups of namespaces.
Multiple application pools can operate at the same time. An application, as defined by its URL, can only be served by one application pool at any time. While one application pool is servicing a request, you cannot route the request to another application pool. However, you can assign applications to another application pool while the server is running.

what is difference between a website and a web application?

0 comments

A website is typically available to the public and contains information, images, documents and links. A web application is interactive software that runs within the framework of the website. For example, Google is a website. Searching on Google however is a web application, or mapping on Google is a web application.

Web applications are often linked to databases to capture or display data via a webpage. The key is that the applications can run in a web browser, preferably without installing any other software, and preferably without having to modify firewall or security settings to run.

October 29, 2008

Difference between batchfiles and windows scripts

0 comments

BatchFiles are scripts tooooooo. They let u script a series of tasks, run programs, etc.
1.The major limitation is that they only let us startup programs and dont provide a way to interact with objects.They work at the level of whole programs and files.
2.Scripting is a more and modern approach for windows automation.
3.Scripting languages have the advantages of using control stuctures like loops and decision structures, which the batch script lacks.

October 01, 2008

Difference between client-side and server-side scripting

1 comments

Take the two scripting languages and try to compare between them
Java Script - client-side scripting
PHP - server-side scripting

The difference between these scripts is JavaScript is interpreted by the web browser once the page that contains the script+html has been downloaded. Whereas server-side scripting languages are interpreted by the web server before the page is even sent to the browser. And once it's interpreted, the results of the script replace the server-side scripting language code in the web page itself. i.e., only the output of the script is placed and sent to the web browser and all the browser sees is a standard HTML file.The script is processed entirely by the server, hence the designation: server-side language.

These server-side scripts when executed allow the web developers to control what appears in the browser window more flexibly than what standard HTML do.

September 30, 2008

Why Scripting?

0 comments

scripting is done if there is any repetitive task(such as changing a pwd for a user).You may think of a sqrt() function in a Math library. Because this function is written once and called whereever required. Scripting is much like the same from birds eye view. In scripting there will be much interaction with hardware, kernel services and OS routines.These are used extensively to accomplish a task which internally may involve some series of tasks.The following def will give you a clear picture abt scripting "A program containing series of commands(services/other commands/etc) arranged accordingly to accomplish a goal" is called a script

September 29, 2008

play with ur browser

0 comments

hey try these

1)
ctrl + + keep pressing this

To restore changes ctrl + 0(zero)

you can try this in mozilla, IE, chrome, safari

2)
press F11 to view your window in fullscreen mode

measure ur browser memory

0 comments

Hey i found this new thing with my chrome browser
It has an intresting feature which helps you to look at the memory limit occupations of all the browsers installed on ur machind.
Just open the chrome browser window. On the top of the window just right click and open taskmanager.
You can see a small taskmanager window where you have to select the chrome browser window and at the bottom click on the 'stats for neds' you will see a new tab which will list the memory usage of all the currently opened browsers.......

Have a nice day:)

Intro to silverlight

0 comments

Silverlight
An added piece of program for the browser(IE) that extends its functionality. Extending the functionality means user can have more real experience with the browser.Its a microsoft product - so by default it will(& should) work on IE browsers. Other browsers do support this technology.Few are Firefox and safari.
Last but not the least silverlight is a client-side technology.

what are plug-ins?

0 comments

Plug-ins are software pieces that enhances the functionality of the existing software. For ex you can add plug-ins to your browser so that you can view files in a different(new) formats.
There are also plug-ins for graphic programmes.
The term plug-ins is used in conjuction with browsers mostly because browsers will keep on upgrading!!!!!

what is managed && unmanaged code?

0 comments

As far as my knowledge the following statements will help you to differentiate between managed & the unmanaged code:

As the name unmanaged code implies the code is completely not in control which indirectly tells us that its a third party software. You are executing a third party software on ur machine and you dont know how it works but yet it works exhibiting its interface to the outside world.

managed code in other words are generated by ur machine - for example a simple c++ program compiled by a borland compiler will generate a file which can be run directly on the same machine. Here the compiler has generated the output(infact it created the origin) where by we can say that the output is managed code for the compiler.
If you wrap this code into an exchangable component(like a dll) and give it to someone else your code will be unmanaged code to the machine which uses your code.
Ex: - Internet Explorer is an example of unmanaged code bcoz it can run .aspx files written and compiler by the .net framework

September 21, 2008

static in java and c#

0 comments

Java:
In java if you don't wanna create an instance of a class. Simply put a private constructor in that class.

C#
In C# also u can follow the same approach but the .net platform provides a simple feature called static class.Look at the following code:

static class MyClass
{
static void hello()
{
Console.WriteLine("Hello World");
}
}
This class can only contain static data.

Note: You can't find static classes in java

September 20, 2008

Instructions to keep in mind before developing an application

0 comments

1. Is it needed?
2. Where to start(Either bottom-up/top-down approach)?
3. Naming conventions
4. Is it extensible -- i.e., will it work for n
5. Reusability - can ur code will be used elsewhere?
6. Am i writing like a good programmer?
7. Performance issues - will it upgrade/degrade performance

September 19, 2008

Some Facts

0 comments

1. Honey is the only food that won't spoil

2.Bullet proof vests, fire escapes, windshield wipers and laser printers they have one thing common
----- they are invented by women
3. pig cannot look up into the sky

4. Butterflies taste with their feet

5.stewardesses is the only word that can typed with left hand

6. Rats multiply so quickly that in 18 months, two rats can have millions have of descendants

7. The ciggarette lighter was invented before the match box.

8. Elephants are only animals that cant jump

9.If a statue of a person in the park on a horse has both front legs in the air, the person died in battle.
If the horse has one front leg in the air, theperson died as a result of wounds received in battle.
If the horse has a all four legs on the ground, the person died of naturalcauses.

10. The strongest muscle in the body is tounge

Tips to remember

0 comments

The most important for a any programmer/software professional is
"knowing how to find what you need, when you need it"

C# - Access specifier for methods

0 comments

If you wirte a function in a class and dont specify any access specifier for that class, then the default access for that function is Private. Which implies that it is not accessible to any class(either child class or not) within that namespace or outside that namespace.

If you want everyone to access that function give it public access. If you want only child classes to access that function give it protected access.

Note:If you gave public access for that function and there default access for the containing class then you will not have access for that public function outside the namespace. This is because you have opened the room door(function is public) but u haven't opened the main door(class not public) for pupil outside the namespace

Display table data in reverse order

0 comments

Very rarely you can get into a situation where u want to show the table data in a reverse order i.e., last row displayed first, 2nd row will be last but one and so on....

The first thing that comes into mind for such a query is user order by with desc/asc.
But watch out baby in every case you cannot use order by. Even if u use, it might not show u the desired result.So what to do????????

Here is your solution


SELECT ROWID AS temp, * FROM emp ORDER BY temp DESC;


Dont forget to check out this stmt guyzzzzz

c# - Access levels within namespace

0 comments


Class Constructor Another Class
default default not accessible(cannot
create object)main door(class) is default opened
for others within namespace but not
the room door(constructor)
so they cannot open it.

default public accessible(can create object) - main
door(class) is default opened for others and you
have opened room door(constructor) also so
accessible.

public default not accessible - you made main door(class)
open not only for classes within the namespace but
also for others outside the namespace but you have
not opened the room doors so on one can access it.

public public accessible - Yep Congratulations you have
opened the main
door and also the room door so its accessible.

Caution: Be careful you can loose privacy in the last case

September 18, 2008

Hi

0 comments

This is my first experience writing something on the net n i m very nervous doing this.
Firstly i vud like to say "Hi" to everyone