© 2004 Microsoft Corporation. All rights reserved.

Figure 1 The ASPX Page to Host C++ Code-behind
  <%@ Page Language="C#" 
  Inherits="ManagedCWebForm.ManagedCWebPage" 
%>
<html>
<body>
<form runat=server>
<h2>Favorite ASP.NET Features:</h2>
<% WriteArray(); %>
<br><br><br>
  <asp:Button Text="Sumit Entry" id="m_button" 
    OnClick="SubmitEntry" runat=server /><br/>
  <asp:Label Text="Type your name here" runat=server />
  <asp:TextBox id="m_text" runat=server /><br/>
  <asp:DropDownList id="m_dropDownList" runat=server /> 
  <br/>
  <asp:Label id="m_label" runat=server />
</form>
</body> 
</html>

Figure 3 AppWizard-generated Files

File
Description
AssemblyInfo.CPP
Contains the global attributes for the entire project including such items as the Assembly Description, the version, and the signature file (if you want to use one)
ManagedCPPLibrary.CPP
Holds the source code for the body of the class
ManagedCPPLibrary.H
Includes the definition of elements within the assembly; the code-behind page will be defined and implemented here
ManagedCPPLibrary.PROJ
Visual Studio .NET Project file
ManagedCPPLibrary.SLN
Visual Studio .NET solution file
STDAFX.H
Includes standard C++ header files/definitions
STDAFX.CPP
Drives precompiled header

Figure 4 The Code-behind Page in Managed C++

  namespace ManagedCWebForm
{
public __gc class ManagedCWebPage : 
          public Page
  {
    ArrayList* m_values;
    public:

    CheckBox* m_checkBox;
    Button* m_button;
    TextBox* m_text;
    DropDownList* m_dropDownList;
    Label* m_label;

    ManagedCWebPage() 
    {
      m_values = new ArrayList();
      String* str;
      str = 
         "Separating presentation from execution";
      m_values->Add(str);
      str = "Smooth data integration";
      m_values->Add(str);
      str = "Garbage collection";
      m_values->Add(str);
      str = "Faster execution";
      m_values->Add(str);
    }

    void SubmitEntry(Object* o, EventArgs* e) 
    {
      String* str;

      str = new String("Hello ");
      str = str->Concat(str, m_text->get_Text());
      str = 
         str->Concat(str, new String(" you selected "));
      str = 
        str->Concat(str, 
          m_dropDownList->get_SelectedItem());
      m_label->set_Text(str);
    }

    void Page_Load(Object* o, EventArgs* e)
    {
      if(!IsPostBack) {
        m_dropDownList->DataSource=m_values;
        DataBind();
      } 
    }

    void WriteArray()
    {
      for (int i=0; i<m_values->Count; i++)
      {
        String* str;
        str = 
          dynamic_cast<String*>(m_values->get_Item(i));
        Response->Write("<li>");
        Response->Write(str);
        Response->Write("</li>");
      }
    }
  };
}