Re: <% =expression%> not evaluated in custom control attributes
- From: "Axel Dahmen" <KeenToKnow@xxxxxxxxxxxxxxxx>
- Date: Sat, 16 Dec 2006 04:22:10 +0100
Hi James,
instead of using this (obsolete) ASP expression syntax you should assign the NavigateUrl property in your code-behind file:
void Page_Load(...)
{
myHyperLink.NavigateUrl = S();
}
HTH,
Axel Dahmen
www.dashop.de
----------------------
"James Hawkins" <not@xxxxxxxxxxxx> schrieb im Newsbeitrag news:et50o2d5v667ds9t58ap1f8ouqfec4n8cp@xxxxxxxxxx
Let's say my ASPX page codebehind has a method S() which returns a
string value (of let's say a constant "string").
If I do this (hope all these special chars make it through) on an ASPX
page:
<a href='<%=S()%>'>Link</a>
this renders as one might expect; i.e. S() is evaluated and the html
rendered will be something like:
<a href='string'>Link</a>
With a server control:
<asp:HyperLink
runat="server"
NavigateUrl='<%=S()%>'>
Link
</asp:HyperLink>
I instead get:
<a href='<%=S()%>'>Link</a>
i.e. the expression is not evaluated. This appears to be the same for
most or perhaps all attributes of most or perhaps all server controls.
I'm creating a custom control (derived from WebControl) where I would
prefer to have these expressions evaluated in attributes (or at least
some of them) before they are passed to the control. I'd imagine that
this is probably done by specifying an attribute for the control
property or perhaps for the control as a whole, as the evaluation
needs to occur prior to the attribute value being passed to the
control, which has no context for evaluation at that point.
The control in question is not data bound.
Is this possible? Is it perhaps possible with a different syntactical
construction; e.g. perhaps with <%# %>?
(VS2005, ASP.NET2.0)
.
- References:
- <% =expression%> not evaluated in custom control attributes
- From: James Hawkins
- <% =expression%> not evaluated in custom control attributes
- Prev by Date: HELP: (ASP.NET 2.0) - Can't get CSS HtmlLink Element working in VS Designer
- Next by Date: Persisting Columns property in Designer for a GridView inside a CompositeDataBoundControl
- Previous by thread: Re: <% =expression%> not evaluated in custom control attributes
- Next by thread: custom web control +client-side javascript + postback
- Index(es):
Relevant Pages
|