Member Info
-
Play Item
How ASP.NET Creates Page Object - an Overview
By 5minOverview on how ASP.NET initialize all the controls on the…
-
Play Item
Restoring the Windows Registry from a Back-up
in SoftwareThere are times when the Windows Registry becomes corrupted to the point…
-
Play Item
Swimming Techniques Common Flaws Consequences
in GeneralJay Dicharry, director of the SPEED Performance Clinic, discusses what swimming technique…
-
Play Item
Genetic Test For Kids' Hearing Loss
in GeneralThis medical video looks into genetic testing for hearing loss.
-
Play Item
Aries and Sagittarius
in AstrologyHey baby, what's your sign?' It might be the cheesiest pickup line…
How to Initialize the ASP.NET Control
More DIY videos at 5min.com
Published: Jun 11, 2009
Video Summary:
Video Tags:
Source: How to Initialize the ASP.NET Control
Video Transcript: (More)
Video Summary:
Learn how to initialize the ASP.NET Label Control with static text.
Video Tags:
aspnet controls initialization, microsoft visual c, visual studio 2005, Microsoft Windows, web development, total training
Source: How to Initialize the ASP.NET Control
Video Transcript: (More)
Now, let us think about initialization. We have initialized that control with some static text. The text box, we are not going to initialize because the user will enter stuff in there. The list box we have entered by code in the page load method. The buttons do not need any initialization, we will handle some events later. The time stamp label does need some initialization. So, let us think about where we are going to put that. We cannot really put that in the mark up because it is clearly is going to change each time we run the web page. So, we really must put it into the code behind class. So, if we had been back up the code behind class and in the page load method.
Remember the page load method is invoked every time the page is requested. If we put code inside this section, the IsPostBack then the initialization will only happen on the first visit. But we need to initialize the time stamp every time the page is refreshed. So, we need to put that code outside the statement here. So, let us do that. TimeStampLabel.text=DateTime.Now, that will give us the current date and time and then I’ll convert that into a string and that will display the time stamp label on the page. Okay, I think it must be time to test the page again. So, let us Control-F5 it and see what it looks like now.
So, I will enter a fictional name in here, John and let us choose some countries, Australia, France. Now, I wanted this to be a multiple selection list box incase I want to visit more than one country in the year. So, that is not working yet because we need to set the multiple selection mode on that list box. What about these buttons here. Well, these buttons do close a post back but obviously we have not handled the events yet so there is nothing standing happening at the moment. So, that is something to do as well. So, let us go back and close the window and go back into the web page default.aspx and in design mode.
So here, we would have the list box and the list box has a selection mode property and currently it is set to single so, I can only choose one item from the list box. Let us set that to multiple so I can select multiple items and let us run it again, Control-F5 and just make sure we can indeed select multiple items. Great, so let us close the web page and think about where we are going to go next.
Remember the page load method is invoked every time the page is requested. If we put code inside this section, the IsPostBack then the initialization will only happen on the first visit. But we need to initialize the time stamp every time the page is refreshed. So, we need to put that code outside the statement here. So, let us do that. TimeStampLabel.text=DateTime.Now, that will give us the current date and time and then I’ll convert that into a string and that will display the time stamp label on the page. Okay, I think it must be time to test the page again. So, let us Control-F5 it and see what it looks like now.
So, I will enter a fictional name in here, John and let us choose some countries, Australia, France. Now, I wanted this to be a multiple selection list box incase I want to visit more than one country in the year. So, that is not working yet because we need to set the multiple selection mode on that list box. What about these buttons here. Well, these buttons do close a post back but obviously we have not handled the events yet so there is nothing standing happening at the moment. So, that is something to do as well. So, let us go back and close the window and go back into the web page default.aspx and in design mode.
So here, we would have the list box and the list box has a selection mode property and currently it is set to single so, I can only choose one item from the list box. Let us set that to multiple so I can select multiple items and let us run it again, Control-F5 and just make sure we can indeed select multiple items. Great, so let us close the web page and think about where we are going to go next.





No comments yet.