Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET ASCX Use of Instance Variable

Let's say I have an ASCX user control that requires access to the current user's full name. An ASPX page contains this line at the top

<%@ Register src="top.ascx" tagprefix="custom" tagname="top" %>

and this line in the body:

<custom:top runat="server" />

The ASPX file knows the user ID of the current user and could determine his full name. So how can I use the code run by the ASPX file to provide its information to the ASCX file?

like image 856
user1325179 Avatar asked Dec 27 '22 02:12

user1325179


1 Answers

Declare a property on the UserControl and have the parent page set it.

On your usercontrol:

public string FullName { get; set; }

On the aspx page either set it in the code behind

YourUserControl.FullName = FullName

or through markup

<custom:top runat="server" FullName="<%= SomeProperty %>" />
like image 157
Brandon Avatar answered Feb 24 '23 09:02

Brandon