Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I followed Rob's blog post, and made a slightly different control. The control is a conditional one, really just like an if-clause:</p> <pre><code>&lt;wc:PriceInfo runat="server" ID="PriceInfo"&gt; &lt;IfDiscount&gt; You don't have a discount. &lt;/IfDiscount&gt; &lt;IfNotDiscount&gt; Lucky you, &lt;b&gt;you have a discount!&lt;/b&gt; &lt;/IfNotDiscount&gt; &lt;/wc:PriceInfo&gt; </code></pre> <p>In the code I then set the <code>HasDiscount</code> property of the control to a boolean, which decides which clause is rendered. </p> <p>The big difference from Rob's solution, is that the clauses within the control really can hold arbitrary HTML/ASPX code.</p> <p>And here is the code for the control:</p> <pre><code>using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebControls; namespace WebUtilities { [ToolboxData("&lt;{0}:PriceInfo runat=server&gt;&lt;/{0}:PriceInfo&gt;")] public class PriceInfo : WebControl, INamingContainer { private readonly Control ifDiscountControl = new Control(); private readonly Control ifNotDiscountControl = new Control(); public bool HasDiscount { get; set; } [PersistenceMode(PersistenceMode.InnerProperty)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public Control IfDiscount { get { return ifDiscountControl; } } [PersistenceMode(PersistenceMode.InnerProperty)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public Control IfNotDiscount { get { return ifNotDiscountControl; } } public override void RenderControl(HtmlTextWriter writer) { if (HasDiscount) ifDiscountControl.RenderControl(writer); else ifNotDiscountControl.RenderControl(writer); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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