In inline style, both the HTML tags and the VB/C# code are stored in the ASPX file. The VB/C# code are in
<script runat='server'> .... </script>tags in the ASPX file.
Visual Studio also supports a programming style known as code-behind. In this style, the ASPX file is mainly for the HTML tags, while the VB/C# code is in a separate file (aspx.vb or aspx.cs).
To convert the sample code to code-behind style, one simply needs to move the code from the
<script runat='server'> .... </script>tags in the ASPX file to the code-behind file. The followings are the detail steps:
- Assuming we start with a new Web Form that is created by Visual Studio.
- Drag and drop the appropriate number of controls from the Visual Studio toolbox to the Web Form. For example, if the sample code needs four WebChartViewer controls, drag and drop four WebChartViewer controls to the Web From.
- Double click on the blank web page. Visual Studio should automatically jump to the code-behind file and automatically create a Page_Load event handler.
- Include the ChartDirector namespace in the by putting the following code at the top of the code-behind file:
- Copy and paste all code inside the Page_Load event handler in the ASPX file to the Page_Load event handler generated by Visual Studio in the code-behind file.
- In some sample code, there are other functions defined in
<script runat='server'> .... </script> tags. Cut and paste those functions to the code-behind file as well.