Sayfalar

5 Şubat 2011 Cumartesi

The Code Editor


Many of Visual Studio’s handiest features appear when you start to write the code that supports your
user interface. To start coding, you need to switch to the code-behind view. To switch back and forth,
you can use two buttons that are placed just above the Solution Explorer window. The tooltips identify
these buttons as View Code and View Designer. When you switch to code view, you’ll see the page class
for your web page. You’ll learn more about code-behind later in this chapter.
ASP.NET is event-driven, and everything in your web-page code takes place in response to an event.
To create a simple event handler for the Button.Click event, double-click the button in design view.
Here’s a simple example that displays the current date and time in a label:
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Current time: " + DateTime.Now.ToLongTimeString();
}
To test this page, select Debug ➤ Start Debugging from the menu. Because this is the first time
running any page in this application, Visual Studio will inform you that you need a configuration file that
specifically enables debugging, and will offer to change your current web.config file accordingly


Click OK to change the web.config configuration file. Visual Studio will then start the integrated test
web server and launch your default browser with the URL set to the current page that’s open in Visual
Studio. At this point, your request will be passed to ASP.NET, which will compile the page and execute it.
To test your event-handling logic, click the button on the page. The page will then be submitted to
ASP.NET, which will run your event-handling code and return a new HTML page with the data

Hiç yorum yok:

Yorum Gönder

Bing'ı Seviyoruz. :)
Google'ı Seviyoruz. :)