- If you want to rename a webpage in Visual Studio, rename the
page using the Solution Explorer. Do not simply rename the file
using Windows Explorer. This will corrupt the project.
- You don't have to wait until a Visual Studio project is
completely debugged to move the C# code from the code-behind file
to the .aspx file in script tags. You can move the C# code as soon
as you wish, then continue to work on the project.
- For a webpage to find images in a Visual Studio project, the images
must be added to the project. Put the images in the same folder as
the .aspx file that will access the images. Then add each image
to the project like this: main menu Project >> Add Existing Item >>
double click on the image.
- Put all your code for Project 2 in a Page_Load event handler.
You can obtain the header for this event handler in Visual Studio by
going to Design mode and double clicking on the page, but not on
any control. Here is the header produced:
protected void Page_Load(object sender, EventArgs e)
{
}
- Here is how to obtain the current date and time and display them
in the Literal control litDateTime using C#:
DateTime d = DateTime.Now;
litDateTime.Text = d.ToString( );
- Use this if statement for deciding which image to display
for the hour. d represents a DateTime object that contains the current
date (see previous hint):
if (d.Hour >= 6 && d.Hour <= 18)
{
// display the sun image.
}
else
{
// display the moon image.
}
- Here is suggested pseudocode for the event handler:
public void Page_Load(object sender, EventArgs e)
{
Declare variables.
Get current date.
Display current date.
if time is between 6:00 and 18:00,
show sun image.
else
show moon image.
Use if..else statement to display month name
and month image depending on value of d.Month.
}