Modify the stand-alone class to resemble the following example. Finally, note that there is no definition for the static field Name this is defined in the CodeBehindExampleUserControl class. The definition of the CodeBehindExampleUserControl class is described in a subsequent step of this procedure. Additionally, the code-behind partial class inherits from a class called CodeBehindExampleUserControl and not the UserControl class as in the previous procedure. You are using a partial class in the code-behind file and the CodeFile attribute of the Page directive in the. Public partial class CodeBehindExampleUserControl_Migrated : 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
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |