Home
Forums
New posts
Search forums
Articles
Latest reviews
Search resources
Members
Current visitors
Newsgroups
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft ASP .NET
User Control Code-Behind
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="rn5a, post: 9525444"] I am lost at what you are getting at. So am I :-) OK.....Let me try to clarify: I have an ASPX page named MyPage.aspx. The logic of this ASPX page is encapsulated in a code-behind named MyPage.aspx.vb. The class in MyPage.aspx.vb is named "MyPageCB". I inherit this code behind in the ASPX page using the following Page directive: <%@ Page Language="VB" Inherits="MyPageCB" %> The ASPX page also uses a user control named MyUC.ascx.The user control has 2 TextBoxes. I register this user control in the ASPX with the following Register directive: <%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %> Using the above TagPrefix & TagName, I add the user control to the ASPX page using the following code: <form runat="server"> <UC:MyUserCtrl ID="muc" runat="server"> </form> I want to set the properties of "muc" which I have to do in MyPage.aspx.vb since MyPage.aspx encapsulates only the server controls; the entire logic is in the code behind MyPage.aspx.vb. Now how do I declare the user control & set its properties in the code-behind of the ASPX page which is named MyPage.aspx.vb? I approached it this way: 1. Created the user control code behind (*.vb) using namespace & class -- sample code Namespace MyUC Public Class UCCodeBehind : Inherits UserControl 'the entire user control logic comes here End Class End Namespace 2. Created the user control (MyUC.ascx) 'insert this line to refer to the code behind class created in step 1 <%@ Control Language="VB" Inherits="MyUC.UCCodeBehind" %> 'only the server controls like TextBox etc. come here; logic already exists in step 1 3. Created the ASPX code behind (MyPage.aspx.vb) importing the proper namespace 'Use this code Imports MyUC Public Class UCPage : Inherits Page Protected WithEvents muc As MyUC.UCCodeBehind Sub Page_Load() 'use user control's properties & methods here End Sub End Class 4. Create the ASPX page (MyPage.aspx) 'Register user control & inherit from code behind <%@ Page Language="VB" Inherits="UCPage" %> <%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %> The above approach works fine but what I would like to know is when an ASPX page uses a code behind which has all the logic as well as uses a user control (like here the ASPX page MyPage.aspx uses the code behind MyPage.aspx.vb & at the same time uses the user control MyUC.ascx), is it always necessary to create a code behind for the user control to access the properties, events etc. of the user control? Or is there some other way out? I hope I have expressed myself lucidly.... [/QUOTE]
Verification
Post reply
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft ASP .NET
User Control Code-Behind
Top