Partial Class CodeBehindExampleUserControl_Migrated In the user control created in the previous procedure, make changes so that the user control resembles the following example. Remove the assembly created in the previous procedure. To access a code-behind class using the ASP.NET 2.0 coding pattern The StandAlone class in turn accesses the Name field of the CodeBehindExampleUserControl user control. The CodeBehindExample page creates an instance of a new StandAlone class. The page should return a concatenated string, "StandAlone + CodeBehindExampleUserControl". Request the Web page CodeBehindExample.aspx in a browser to verify that it works in the. vbc /target:library /nologo /out:bin\CodeBehindExampleVB.dll controls\ StandAlone.vbĬsc /target:library /nologo /out:bin\CodeBehindExampleCS.dll controls\ StandAlone.cs In the next procedure, you will use a partial class in the code-behind class and replace the CodeBehind attribute with the Codefile attribute.Ĭreate a Bin folder in your Web application if one does not already exist, and compile the Web page, user control, and stand-alone class into an assembly as shown in the following example. In this example, you are using a class in the page's code-behind file and the CodeBehind attribute of the Page directive in the. In the root of your Web application, create a Web page with a code-behind class as shown in the following example. Return _name + " + " + CodeBehindExampleUserControl.Name Return _name & " + " & CodeBehindExampleUserControl.Name Public ReadOnly Property Name() As String In the root of your Web application, create a stand-alone class as shown in the following example.
In the next procedure, you will use a partial class in the code-behind class and replace the CodeBehind attribute with the Codefile attribute. In this example, you are using a class in the control's code-behind file and the CodeBehind attribute in the Page directive in the. Public static string Name = "CodeBehindExampleUserControl" Public class CodeBehindExampleUserControl : Protected Sub Page_Load(ByVal sender As Object, _īyVal e As System.EventArgs) Handles Me.Load Public Shared Name As String = "CodeBehindExampleUserControl" Public Class CodeBehindExampleUserControl In this folder, create a user control with a code-behind class, as shown in the following example. In the root of your Web application, create a folder called Controls. To access a code-behind class using the ASP.NET 1.x coding pattern The procedures in this topic require the. The pattern uses an abstract base stub class in the App_Code directory. This topic demonstrates a coding pattern to enable a Web application that contains stand-alone classes that reference code-behind classes to successfully compile and run. In ASP.NET 2.0, the page compilation, by default, results in multiple assemblies references from the stand-alone class to the code-behind class will result in a compilation error. In previous versions of ASP.NET, all pages in a Web application are compiled into a single assembly so that references from the stand-alone class to the code-behind class can be resolved. The stand-alone class example used in the following procedures accesses a static field in another control's code-behind class.
This topic demonstrates how to migrate an ASP.NET version 1.x stand-alone class to ASP.NET version 2.0.