Scenario :
Default.aspx is as below.
<%@ Page MasterPageFile="~/StandardLayout.master" Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register src= "~/Controls/Us.ascx" tagname="AboutUs" tagprefix="site" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
<div id="large">
<site:AboutUs ID="AboutUsControl" runat="server" />
</div>
<div id="small">
<site:AboutUs ID="AboutUsControl" runat="server" />
</div>
</asp:Content>
AboutUs.ascx.cs assigns some value to a label control. In the above scenario, I want to re-use AboutUs within “div id=small” as the logic is same but only value change.
My question is within AboutUs.ascx.cs, I need some way to find out if it belongs within “”, assign Label1 = “I am here”. Otherwise Label1 = “I am everywhere”
I am trying to pass parameters but do I need to anything in the code-behind in default.aspx.cs? or any other suggestions.
Please suggest.
Make sure both user controls have unique ID’s. I’ll use AboutUsControl1 and AboutUsControl2. Declare a name property for your user control:
And in the code behind on the page using the user controls, just pass the value by calling the public variable:
or just set doWhat in the control itself: