Re: Strange Custom Control Problem (.Net 2.0)



Thanks for your reply Tomasz,

Yes, I agree that Binding Expression is not quite convenient for value
assignment cases. I think that's why "code expression bulder" is added in
ASP.NET 2.0 which is quite flexible and powerful :)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
From: "Tomasz J" <oegweb@xxxxxxxxxxxxx>
References: <#an5P0lUIHA.4768@xxxxxxxxxxxxxxxxxxxx>
<spXdCfpUIHA.4720@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: Strange Custom Control Problem (.Net 2.0)
Date: Wed, 9 Jan 2008 16:30:32 +0100

Thank you Steven!

I was unaware of this limitation. This syntax worked with my ascx controls.
Good to know. Perhaps it is something which could be improved, because
binding is less convenient.

Tomasz J


"Steven Cheng[MSFT]" <stcheng@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:spXdCfpUIHA.4720@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi Tomasz,

As for the problem you met, it is due to the limitation of expression
that
can be used inside ASP.NET server control attribute/tag. The <%= %>
expression is brought from classic ASP for compatible purpose and can
only
be used in plain html fragment(at top level of aspx page or ascx user
control).

For ASP.NET server control tag, you can consider the following means to
embed dynamic value:

1. Use <%# ... %> like databinding expression, however, you need to call
control.DataBind() at runtime (in page load or init ...) so as to make
the
databinding expression get evaluated.

2. In ASP.NET 2.0, there provides a custom Expression Builder
functionality, that can help you define your own custom expression(can be
used inside server control tag/attributes). Here are some articles
introducing this:

#The CodeExpressionBuilder

http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionB
uilder.aspx

http://weblogs.asp.net/leftslipper/archive/2007/01.aspx

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no
rights.


--------------------
From: "Tomasz J" <oegweb@xxxxxxxxxxxxx>
Subject: Strange Custom Control Problem (.Net 2.0)
Date: Wed, 9 Jan 2008 02:15:06 +0100


Hello Developers,

I have a control derived from System.Web.UI.WebControls.WebControl.
Control
has this property:

[Bindable(true), Category("Misc"), Description("value")]
public string Value
{
set { _value = value; }
get { return _value; }
}

protected override void AddAttributesToRender(HtmlTextWriter writer)
{
base.AddAttributesToRender(writer);
writer.AddAttribute("alt", _value);
}

I use my control like this:
<mc:MyControl ID="MyControl" Value="<%=Value %>" runat="server" />

(the page class has protected Value property)

There are no compilation problems, but ASP.Net incorrectly renders alt
attribute:

alt="&lt;%=Value %>"

It seems like it is a problem at compile-time. I cannot use expressions
in
control attribute values.
What could be wrong with this picture?
Any hints highly appreciated.

Tomasz J








.



Relevant Pages

  • Re: Menu control Databinding problem using StaticItemTemplate
    ... it's a pity that the MenuItem class is a sealed class that can not ... Microsoft MSDN Online Support Lead ... As for adding custom attributes to ASP.NET 2.0 Menu control, ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: user control in an aspx page
    ... Microsoft MSDN Online Support Lead ... user control in an aspx page ... it can also be a custom server control. ...
    (microsoft.public.vsnet.general)
  • RE: dataTargets in web control
    ... or you can even use code to add custom attribute ... Microsoft MSDN Online Support Lead ... You can send feedback directly to my manager at: ... Subject: dataTargets in web control ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: asp:DropDownList and Javascript
    ... Microsoft MSDN Online Support Lead ... You can send feedback directly to my manager at: ... Subject: asp:DropDownList and Javascript ... Is there any way to determine which control initiated the PostBack? ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: ObjectList Data-Binding to a List
    ... Yes, mobile control is ... as most smart devices not support html and asp.net standard ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework.aspnet)

Quantcast