Tuesday, April 9, 2013

Page Life Cycle


PreInit 
PreInit is the first phase in asp.net page life cycle events. This is the place where one can dynamically set their master page in the code. In such case you can also set any theme or skin to your page, in PreInit we can also set the properties of the server controls of Master page, like the code below:

protected void Page_PreInit(object sender, EventArgs e)
{
if (textBox1 == null)
       {
          Response.Write("Pre Init, server control Not available");
       }
       else
       {
          string TextinInit = textBox1.Text;
          Response.Write("Pre Init, Server Control enabled");
       }

Page.MasterPageFile = "~/TestInitMaster.master";

       TextBox _mstTextBox = (TextBox)Page.Master.FindControl("txtMessage");
       Label _mstLabel = (Label)Page.Master.FindControl("lblMessage");

       _mstLabel.Text = "Setted in default page at time : " +ateTime.Now.ToString();
       _mstTextBox.Text = "Textbox set in default page";
  }

In above you can see I’ve used a master page dynamically and set a label and TextBox’s Text property of that master page in runtime that means we can set the master page dynamically and associate the values in their controls if any. If you try to set the masterpage in any other event after Page_PreInit event, you will get an error message that will tell you that the master page only can be set on or before Page_PreInit event. In Page_PreInit event you can also see at the top level I’m checking a TextBox1 value whether it’s null or not. It is a server control (TextBox), but in PreInit the value will always be null of this text box or any other server control. So if I want to conclude the thing, in Page_PreInit controls are not fully initialized. So use this event for setting MasterPage file in your code. Each control Unique ID’s are also available at this event.

Init  
Init is called when you can initialize your page controls, this is the place that comes into picture after each Control initialization, till this event they get their Unique Id, master page etc. In Init you cannot access any controls properties after the last viewstate, I mean suppose you enter some text in a textbox control and click on a button control that makes a postback, now you want to view the value latest entered. In such case you will be able to see the textbox value which you’ve entered after the round trip happens, this is because of ViewState property of controls. That means they preserved your last saved value, but you see this value after Init phase because, usually we don’t use these events in our code and use just Page_Load event where the Viewstate value already got loaded. But as in Init phase, we cannot access our latest entered values in textbox, so in Init you won’t be able to get the latest changes. So I can say in Init we won’t be able to get the postback value.

InitComplete
In this event, Viewstate functionality is turned on for server control. Viewstate of controls allows preserving their values across postback.

PreLoad
This is the first event where viewstate functionality starts retrieving their values. PreLoad executes after InitComplete method. In this method, page has loaded values from viewstate. So for example in a button click event if you create a viewstate like below than what will going to be happen:

protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ViewState["myData"] = "just a text string";
        }

After button click, postback will happen at it will start calling page events like PreInit, Init, Initcomplete. Till these three events you will not be able to get the value of Viewstate “myData”. Even when the event fires PreLoad event of page, at this time you cannot access the ViewState, this is because ViewState will set the value when asp.net reaches the ButtonClick event, and this will happen after Load event, so one more time we will click on our submit button, and because now the ViewState[“myData”] resides into my page, I can access it on my PreLoad event. For better understanding please see the screen shot below:
ASP .Net page life cycle

Load
Most of the developers are familiar with the page load, as this is the only event that comes by default in aspx.cs page when you start doing anything with your code behind. The page Load events executes after the Page_PreLoad event. If you have created your own Load method in constructor of your code behing, then this will be the method that will execute before the Page_Load event and after Page_PreLoad event, for better understanding refer to the image below:
Init event in Page Life Cycle


As you are seeing in above code, I’ve created my own Page_Load event in my code behind as well as the default Load event, I didn’t mention Page_PreLoad event here, but it will execute after Page_InitComplete event. So back to the image, the _Default_Load will execute first before the Page_Load event. If you have any master page in your page, then the Load event of your master page will run followed by the user control Load event if they exist in your file.

Events
After the Page_load the next event is Page Control’s event. For example, if you have a control that raises postback just like button, and you clicked on the Button, so after Page_Load your Button_Click event will fire, and do the rest of the thing you’ve mentioned in your page. for better understanding please refer to the image below, event execution will be happen in that sequence how image is showing, in event portion whatever you will do that will go ahead and will do the things you’ve mentioned in you page. just like below, I said to create a ViewState[“myData”] and put some string inside that viewstate. So now the viewstate is ready to preserve ahead in my code. 

In Events you can also check the Page.IsValid property if you’ve used any validator controls in your page like regularexpressionValidator, requiredFieldValidator, Range etc. To check this property refer to the image below.
Load complete event of Page Life Cycle


LoadComplete
This event can be used when all the event processing has been done in the page.

PreRender/PreRenderComplete 

PreRender event gets called when page has created all the controls that user will see in his browser. PreRenderComplete is the last place to change anything in the page. After this event any changes will not get preserved in page cycle. 

SaveStateComplete
event gets fired immediately after the PreRenderComplete event, in this event the viewstate functionality and control state get saved, as I said in PreRenderComplete changes can be done that will affect the next postback. In SaveStateComplete you can do the changes in your server control, but the state won’t be available in next postbacks. 

Render 
Render is not an event but this is the phase where the HTML of your page will get rendered to the output stream with the help of HTMLTextWriter. You can override the Render method of page if you want to write your own code rather than the actual HTML text. As like below:

Render event of Page Life Cycle

As you can see in the code above, I’ve override the Render method in my code and write something with Heading 1 tag and later on called the base.render method. In current scenario the thing will happen is: apart my server controls code in my browser I’ll be able to see my Hello world text also. If I remove the base.render method calls, than I won’t be able to view my any control if I’ve created in page.


Unload 
This is the last event that gets fired. This is the page cleaning process like closing the open file connections etc, so in this process you cannot do any kind of manipulation with data that affect the rendering, you are restricted to use Response property also, and doing such you will get an exception message.

There might be some mistakes with this article but I tried my best to share with you, So if you have some queries OR suggestions please feel free and share the by comment. Thank you for reading this post..
- See more at: http://www.codeimagine.com/2012/09/define-page-life-cycle-events-asp-net.html#sthash.L23gBcGB.dpuf

Monday, April 8, 2013

=== vs == in Javascript

JavaScript provides two comparison operator strict equality (===) and normal or lenient equality(==)

Strict Equality only compare the value if their types are equal .Values with different type can never be equal.Triple equals do the exact comparison of the actual value.

if(5==="5") //false

if(' '===0) //false

if(3===3) //true

Lenient Equality  compare the value with different type ,then type coercion will occur means if you are comparing string with number then browser will convert string to number before values comparison.Likely for Boolean and int comparison.

if(5=="5") //true

if(0==false) //true

Inequality is  similar as above

if using != operator then because of type coercion below examples are giving unexpected result

if(9!="9") //false

if(0!=false) //false

use !== operator to see the desired output

if(9!=="9")  // true

if(0!==false) // true


Thursday, March 21, 2013

THE WOMAN IN YOUR LIFE

  *To all the guys who read this…..please read fully and understand…………..*
 *To all the girls who read this………... An excellent forward……please read
fully..... and forward to the boys you know………. *
 *This is a beautiful article : **
T he woman in your life...very well expressed.... *


Tomorrow you may get a working woman, but you should marry her with these
facts as well.

Here is a girl, who is as much educated as you are;
Who is earning almost as much as you do;

One, who has dreams and aspirations just as
 you have because she is as human as you are;

One, who has never entered the kitchen in her life just like you or your
Sister haven't, as she was busy in studies and competing in a system
that gives no special concession to girls for their culinary achievements

One, who has lived and loved her parents & brothers & sisters, almost as
much as you do for 20-25 years of her life;

One, who has bravely agreed to leave behind all that, her home, people who
love her, to adopt your home, your family, your ways and even your family
,name

One, who is somehow expected to be a master-chef from day #1, while you
sleep oblivious to her predicament in her new circumstances, environment and
that kitchen

One, who is expected to make the tea, first thing in the morning and cook
food at the end of the day, even if she is as tired as you are, maybe more,
and yet never ever expected to complain; to be a servant, a cook, a mother,
a wife, even if she doesn't want to; and is learning just like you are as
to what you want from her; and is clumsy and sloppy at times and knows that
you won't like it if she is too demanding, or if she learns faster than
 you;

One, who has her own set of friends, and that includes boys and even men at
her workplace too, those, who she knows from school days and yet is willing
to put all that on the back-burners to avoid your irrational jealousy,
unnecessary competition and your inherent insecurities;

Yes, she can drink and dance just as well as you can, but won't, simply
      Because you won't like it, even though you say otherwise

One, who can be late from work once in a while when deadlines, just like
yours, are to be met;

One, who is doing her level best and wants to make this most important,
relationship in her entire life a grand success, if you just help her some
                           and trust her;

One, who just wants one thing from you, as you are the only one she knows in
your entire house - your unstinted support, your sensitivities and most
importantly - your understanding, or love, if you may call it.

But not many guys understand this......
*Please appreciate "HER" *

                  *I hope you will do.... *





*Respect Her.*









CHINESE HOROSCOPE


                
AMAZINGLY ACCURATE 
Whatever you do, don't cheat!
CHINESE HOROSCOPE :
THE YEAR OF THE IRON DRAGON,
WISHING YOU PROSPERITY AND GOOD FORTUNE IN THE
CHINESE NEW YEAR
FOLLOW THE INSTRUCTIONS -
DO NOT CHEAT
OR IT WON'T WORK AND
YOU WILL WISH YOU HADN`T.

TAKE 3 MINUTES
TRY THIS - IT WILL FREAK YOU OUT.
THE PERSON WHO SENT THIS TO ME SAID
HER WISH CAME TRUE 10 MINUTES AFTER SHE FORWARDED THE EMAIL

NO CHEATING !!!!











THIS GAME HAS A FUNNY / CREEPY OUTCOME.
DO NOT READ AHEAD, JUST DO IT.
IT TAKES ABOUT 3 MINUTES - WORTH A TRY

1st. Get PEN and PAPER

2nd. WHEN CHOOSING NAMES, MAKE SURE THEY ARE REAL PEOPLE THAT YOU ACTUALLY KNOW

3rd. GO WITH YOUR FIRST INSTINCTS !!!!! Very important for good results.

4th. SCROLL DOWN
ONE LINE AT THE TIME
DON`T READ AHEAD 

otherwise 

YOU WILL RUIN THE FUN.









1. On a blank sheet of paper, WRITE NUMBERS 
1 through11 in a COLUMN on the LEFT.












2. BESIDE the NUMBERS 
1 & 2 ,
WRITE DOWN ANY
2 NUMBERS YOU WANT.

DO YOU HAVE A FAVORITE NUMBER?














3.. BESIDE the NUMBERS 
3 & 7 ,
WRITE DOWN THE NAMES OF TWO MEMBERS
OF THE OPPOSITE SEX.











CAUTION: DO NOT LOOK AHEAD or IT WILL NOT TURN OUT RIGHT














4. WRITE ANYONES NAME
(like FRIENDS or FAMILY...)
next to
 
4, 5, & 6 .













DON`T CHEAT OR YOU`LL BE UPSET THAT YOU DID













5. WRITE down FOUR SONG TITLES in 
8, 9, 10, & 11




















ARE YOU READY?
HERE IS THE
KEY TO THE GAME


1. THE NUMBER of PEOPLE YOU MUST TELL ABOUT THIS GAME is found in
SPACE 2





2. THE PERSON IN SPACE
IS THE ONE YOU LOVE






3. THE PERSON YOU LIKE but your relationship CANNOT WORK is in
SPACE 7






4. YOU CARE MOST about the PERSON you put in
SPACE 4







5. THE PERSON YOU NAME IN NUMBER 
5 IS THE ONE WHO
KNOWS YOU VERY WELL.







6. THE PERSON YOU NAMED IN 
6 IS YOUR
LUCKY STAR







7.. THE SONG IN 
8 IS THE SONG THAT MATCHES WITH THE
PERSON IN NUMBER 3






8. THE TITLE IN 
9 IS THE SONG FOR THE
PERSON IN 7







9. THE 
10 TH SPACE IS THE SONG THAT TELLS YOU MOST ABOUT
YOUR MIND






10. AND 
11 IS THE SONG TELLING HOW YOU
FEEL ABOUT LIFE






11. NUMBER 
1 IS YOUR
LUCKY NUMBER







Health Tips : IF YOU CARE ABOUT YOUR HEALTH, YOU MUST READ


 
A chat with Dr.Devi Shetty, Narayana Hrudayalaya (Heart Specialist) Bangalore was arranged by WIPRO for its employees. The transcript of the chat is given below. Useful for everyone.  
 
Qn: What are the thumb rules for a layman to take care of his heart? 

Ans:1. Diet - Less of carbohydrate, more of protein, less oil
2. Exercise - Half an hour's walk, at least five days a week; avoid lifts and avoid sitting for a longtime
3. Quit smoking
4. Control weight
5. Control blood pressure and sugar


Qn: Is eating non-veg food (fish) good for the heart?
Ans: No  
Qn: It's still a grave shock to hear that some apparently healthy person   
gets a cardiac arrest. How do we understand it in perspective?
   
Ans: This is called silent attack; that is why we recommend everyone past the age of 30 to undergo routine health checkups. 


Qn: Are heart diseases hereditary?
  Ans: Yes   

Qn: What are the ways in which the heart is stressed? What practices do you suggest to de-stress? 
Ans: Change your attitude towards life. Do not look for perfection in everything in life. 

Qn: Is walking better than jogging or is more intensive exercise required to keep a healthy heart? 
Ans: Walking is better than jogging since jogging leads to early fatigue and injury to joints   

Qn: You have done so much for the poor and needy. What has inspired you to do so? 

Ans: Mother Theresa , who was my patient 


Qn: Can people with low blood pressure suffer heart diseases? 
Ans: Extremely rare 

Qn: Does cholesterol accumulates right from an early age
(I'm currently only 22) or do you have to worry about it only after you are above 30 years of age? 
Ans: Cholesterol accumulates from childhood. 

Qn: How do irregular eating habits affect the heart ?
Ans: You tend to eat junk food when the habits are irregular and your body's enzyme release for digestion gets confused. 

Qn: How can I control cholesterol content without using medicines?

Ans: Control diet, walk and eat walnut.
 

Qn: Can yoga prevent heart ailments? 
Ans: Yoga helps. 

Qn: Which is the best and worst food for the heart? 
  
Ans: 
Fruits and vegetables are the best and the worst is oil. 

Qn: Which oil is better - groundnut, sunflower, olive?
Ans: All oils are bad .. 

Qn: What is the routine checkup one should go through? Is there any specific test?
   
Ans: Routine blood test to ensure sugar, cholesterol is ok. Check BP, Treadmill test after an echo. 


Qn: What are the first aid steps to be taken on a heart attack? 

Ans: Help the person into a sleeping position 
, placean aspirin tablet under the tongue with a sorbitrate tablet if available, and rush him to a coronary care unit since the maximum casualty takes place within the first hour. 

Qn: How do you differentiate between pain caused by a heart attack and that caused due to gastric trouble?
Ans: Extremely difficult without ECG.

Qn: What is the main cause of a steep increase in heart problems amongst youngsters? I see people of about 30-40 yrs of age having heart attacks and serious heart problems. 

Ans: Increased awareness has increased incidents. Also, sedentary lifestyles, smoking, junk food, lack of exercise in a country where people are genetically three times more vulnerable for heart attacks than Europeans and Americans. 


Qn: Is it possible for a person to have BP outside the normal range of 120/80 and yet be perfectly healthy?
Ans: Yes.

Qn: Marriages within close relatives can lead to heart problems for the child. Is it true? 

Ans : Yes, co-sanguinity leads to congenital abnormalities and you may not have a software engineer as a child 


Qn: Many of us have an irregular daily routine and many a times we have to stay late nights in office. Does this affect our heart ? What precautions would you recommend? 

Ans : When you are young, nature protects you against all these irregularities. However, as you grow older, respect the biological clock. 


Qn: Will taking anti-hypertensive drugs cause some other complications (short / long term)? 
Ans : Yes, most drugs have some side effects. However, modern anti-hypertensive drugs are extremely safe. 

Qn: Will consuming more coffee/tea lead to heart attacks? 
Ans : No.

Qn: Are asthma patients more prone to heart disease?
Ans : No. 

Qn: How would you define junk food? 

Ans : Fried food like Kentucky , McDonalds , samosas, and even masala dosas. 


Qn: You mentioned that Indians are three times more vulnerable. What is the reason for this, as Europeans and Americans also eat a lot of junk food? 

Ans: Every race is vulnerable to some disease and unfortunately, Indians are vulnerable for the most expensive disease. 

 
Qn: Does consuming bananas help reduce hypertension?Ans : No. 

Qn: Can a person help himself during a heart attack (Because we see a lot of forwarded emails on this)?
Ans : Yes. Lie down comfortably and put an aspirin tablet of any description under the tongue and ask someone to take you to the nearest coronary care unit without any delay and do not wait for the ambulance since most of the time, the ambulance does not turn up. 

Qn: Do, in any way, low white blood cells and low hemoglobin count lead to heart problems? 
Ans : No. But it is ideal to have normal hemoglobin level to increase your exercise capacity. 

Qn: Sometimes, due to the hectic schedule we are not able to exercise. So, does walking while doing daily chores at home or climbing the stairs in the house, work as a substitute for exercise? 

Ans : Certainly. Avoid sitting continuously for more than half an hour and even the act of getting out of the chair and going to another chair and sitting helps a lot. 


Qn: Is there a relation between heart problems and blood sugar?
 Ans: Yes. A strong relationship since diabetics are more vulnerable to heart attacks than non-diabetics. 

Qn: What are the things one needs to take care of after a heart operation?

Ans : Diet, exercise, drugs on time 
, Control cholesterol, BP, weight..

Qn: Are people working on night shifts more vulnerable to heart disease when compared to day shift workers? 
  Ans : No. 

Qn: What are the modern anti-hypertensive drugs? 
 Ans : There are hundreds of drugs and your doctor will chose the right combination for your problem, but my suggestion is to avoid the drugs and go for natural ways of controlling blood pressure by walk, diet to
reduce weight and changing attitudes towards lifestyles. 


Qn: Does dispirin or similar headache pills increase the risk of heart attacks? 
Ans : No. 

Qn: Why is the rate of heart attacks more in men than in women? 

Ans : Nature protects women till the age of 45. 


Qn: How can one keep the heart in a good condition? 

Ans : Eat a healthy diet, avoid junk food, exercise everyday, do not smoke and, go for health checkup 
sif you are past the age of 30 ( once in six months recommended)

Management Lessons from "3 Idiots" Movie... Life Is Emotion Management Not Intelligence Optimization


  
1. Never Try To Be Successful
Success is the bye-product. Excellence always creates success. So, never run after the success, let it happen automatically in the life.
 


2. Freedom To Life
Don’t die before actual death. Live every moment to the fullest as you are going to
die today night. Life is gifted to humankind to live, live & live @ happiness.
 

3.
 Passion Leads To Excellence 
When your hobby becomes your profession and passion becomes your profession. You will be able to lead up to excellence in the life. Satisfaction, pleasure, joy and love will be the outcome of following passion. Following your passion for years, you will surely become something one day. 


  
4. Learning Is Very Simple
Teachers do fail. Learners never fail. Learning is never complicated or difficult. Learning is always possible whatever rule you apply.
 




5. Pressure At Head
Current education system is developing pressures on students’ head. University intelligence is useful and making some impact in the life but it cannot be at the cost of the life.
 


  
6. Life Is Emotion Management Not Intelligence Optimization
Memory and regular study have definite value and it always helps you in leading a life. You are able to survive even if you can make some mark in the path of the life. With artificial intelligence, you can survive and win but you cannot prove yourself genius. Therefore, in this process genius dies in you.

7. Necessity Is The Mother Of Invention
Necessity creates pressure and forces you to invent something or to make it happen or to use your potentiality. Aamir Khan in this film, 3 idiots, is able to prove in the film by using aqua guard pump at the last moment.
 


  
8. Simplicity is Life
Life is need base never want base. Desires have no ends. Simplicity is way of life and Indian culture highly stresses on simple living and high thinking, and this is the way of life: ‘Legs down to earth and eyes looking beyond the sky’
 




9. Industrial Leadership
Dean of the institute in 3 idiots is showing very typical leadership. He has his own principles, values and ideology, and he leads the whole institute accordingly. This is an example of current institutional leadership. In the present scenario, most of the institutes are fixed in a block or Squarish thinking.
 




10. Love Is Time & Space Free
Love is not time bound and space bound. It is very well demonstrated in this movie same love was demonstrated by Krishna and Meera. Love is border free, time free and space free.
 




11. Importance Of One Word In Communication 
If communication dies, everything dies. Each word has impact and value in communication. One word if used wrongly or emphasized wrongly or paused at a wrong place in communication what effect it creates and how is it affected is demonstrated very well in this movie.



12. Mediocrity Is Penalized 
Middle class family or average talent or average institute is going to suffer and has to pay maximum price in the life if they do not upgrade their living standards. To be born poor or as an average person is not a crime but to die as an average person with middle class talent is miserable and if you are unable to optimize your potentiality and die with unused potentiality then that is your shameful truth. One should not die as a mediocre. He/she has to bring out genius inside him/her and has to use his/her potentiality to the optimum level. 
Lets create a learning environment…..