Note that there are some explanatory texts on larger screens.

plurals
  1. POproblems with binding <%# in Custom Control
    primarykey
    data
    text
    <p>so I've finally started building custom controls instead of using functions which return chunks of HTML ;) But I'm running into a problem. I want to pass parameters to the control, say, "X":</p> <pre><code>&lt;some:MessageControl runat="server" X=&lt;%# "asd" %&gt; /&gt; </code></pre> <p>My code behind looks like this:</p> <pre><code>public partial class MessageControl : System.Web.UI.UserControl { String x = ""; public String X { get { return x; } set { x = value;} } } </code></pre> <p>When I output the value of <code>x</code> in the control,</p> <pre><code>x: &lt;%= X %&gt; </code></pre> <p>it is empty. If I pass on "asd" directly as in</p> <pre><code> &lt;some:MessageControl runat="server" X="asd" /&gt; </code></pre> <p>X gets the correct value.</p> <p>What's happening here? How can I get this to work? Any suggestions are appreciated, Nicolas</p> <p><strong>Edit: Some more context.</strong> Basically I want to be able to insert the control on a number of pages without settings its properties in the code behind, but still be able to set its visibility by calling a (varying) method from the containing page. </p> <pre><code>&lt;%@ Page Language="c#" Src="MyPage.aspx.cs" AutoEventWireup="true" Inherits="MyPage" %&gt; &lt;%@ Register Src="MessageControl.ascx" TagName="MessageControl" TagPrefix="some" %&gt; &lt;html&gt; &lt;body&gt; &lt;some:MessageControl runat="server" Visible=&lt;%# SomeBoolMethodFromContaining Page%&gt; /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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