Note that there are some explanatory texts on larger screens.

plurals
  1. POSet codebehind public property directly from ascx
    primarykey
    data
    text
    <p>I have three usercontrols: <code>usercontrolA</code>, <code>usercontrolB</code> and <code>usercontrolC</code> which <em>all share the same codebehind</em> each having: </p> <p><code>&lt;%@ Control Language="c#" AutoEventWireup="True" Codebehind="usercontrolA.ascx.cs" Inherits="usercontrolA" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %&gt;</code> at the top of the ascx.</p> <p>In the codebehind file I have a public property called <code>ShowAll</code>.</p> <p>I know I can set this property when I put the usercontrol on the page e.g.</p> <p><code>&lt;uc1:usercontrolB ID="usercontrolB1" runat="server" ShowAll="true" /&gt;</code></p> <p>However <em>I would like ShowAll to always be set to true on usercontrolB</em> so would rather not have to set it every time it is placed on a page.</p> <p>I know I can add a script tag to usercontrolB to set ShowAll in <code>Page_Load</code>:</p> <pre><code>&lt;script runat="server"&gt; protected void Page_Load(object sender, System.EventArgs e) { ShowAll = true; } &lt;/script&gt; </code></pre> <p>But want to keep the <code>Page_Load</code> implementation I already have in the codebehind. <strong>Is there any other way to set this property automatically for usercontrolB?</strong></p> <p><strong>Edit:</strong> If it's possible I'd like to be able to set this in the ascx rather than in the code behind, so that someone else later on could add <code>usercontrolD</code> and set <code>ShowAll</code> to true for all instances of <code>usercontrolD</code> without needing to get me to modify and recompile the codebehind.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload