Although it is much easier to write and maintain code with the traditional code behind strategy there are cases when you have to use no code behind. Following are some cases where the no code behind model can come handy:
This topic will describe the basic steps you need to follow when creating no code behind pages using Nevron Chart for .NET.
HTML |
Copy Code
|
---|---|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0"> <TITLE> </TITLE> </HEAD> <BODY> </BODY> </HTML> |
HTML |
Copy Code
|
---|---|
<%@ Import namespace ="System.Drawing"%> <%@ Import namespace ="Nevron"%> <%@ Import namespace ="Nevron.GraphicsCore"%> <%@ Import namespace ="Nevron.Chart"%> <%@ Import namespace ="Nevron.Chart.WebForm"%> <%@ Register TagPrefix="ncwc" Namespace="Nevron.Chart.WebForm" Assembly="Nevron.Chart.WebForm" %> <%@ Control Language="c#" %> |
HTML |
Copy Code
|
---|---|
<%@ Import namespace ="System.Drawing"%> <%@ Import namespace ="Nevron"%> <%@ Import namespace ="Nevron.GraphicsCore"%> <%@ Import namespace ="Nevron.Diagram"%> <%@ Import namespace ="Nevron.Diagram.WebForm"%> <%@ Register TagPrefix="ncwc" Namespace="Nevron.Diagram.WebForm" Assembly="Nevron.Diagram.WebForm" %> <%@ Control Language="c#" %> |
HTML |
Copy Code
|
---|---|
<TABLE id="Table2" style="Z-INDEX: 102; LEFT: 10px; POSITION: absolute; TOP: 10px" cellSpacing="1" cellPadding="1" border="0"> <TR> <TD vAlign="top" align="left" Width="420" Height="320"> <% //add component specific initialization code here //manually create a HtmlTextWriter object which will render the created component in the //context of ASP.NET HtmlTextWriter writer = new HtmlTextWriter(Page.Response.Output); //use the RenderControl method of either the charting or diagramming component //assume that the have created a Chart control chartControl.RenderControl(writer); %> </TD> </TR> </TABLE> |
That's it - now you have an aspx page using no code behind that displays either diagram or chart. Note that you have to match the size of the control passed through the Width and Height properties with the width of the table data. You also have to manually create an HtmlTextWriter object in order to pass it to the RenderControl method of the component.
The no code behind technique is also very useful when you have to directly stream an image to the browser. In this case however the page must not contain any other HTML content other that the code creating and rendering the chart, because the control changes the MIME type to an image MIME type (image/png, image/bmp etc.). Any additional content will confuse the client browser and it will not be able to read the image.