473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Strange Custom Control Problem (.Net 2.0)

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
Jan 9 '08 #1
3 1407
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/infinitiesloo...odeExpressionB
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/subscripti...ult.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/subscripti...t/default.aspx.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Tomasz J" <oe****@nospam.nospam>
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
Jan 9 '08 #2
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]" <st*****@online.microsoft.comwrote in message
news:sp**************@TK2MSFTNGHUB02.phx.gbl...
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/infinitiesloo...odeExpressionB
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/subscripti...ult.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/subscripti...t/default.aspx.

==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
>>From: "Tomasz J" <oe****@nospam.nospam>
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

Jan 9 '08 #3
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" <oe****@nospam.nospam>
References: <#a**************@TK2MSFTNGP02.phx.gbl>
<sp**************@TK2MSFTNGHUB02.phx.gbl>
>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]" <st*****@online.microsoft.comwrote in message
news:sp**************@TK2MSFTNGHUB02.phx.gbl...
>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/infinitiesloo...odeExpressionB
>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/subscripti...ult.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/subscripti...t/default.aspx.

================================================= =
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
>>>From: "Tomasz J" <oe****@nospam.nospam>
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


Jan 10 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Assaf | last post by:
Hi all. Can't explain this.... I am using custom control COCA that includes an Image IMAGO. IMAGO raises the Click event for COCA when clicked. All good so far. The custom control COCA is...
1
by: Kepler | last post by:
I'm fighting a really strange bug that involves both a DataGrid and a Repeater disappearing on postback. The strange thing is that I've distilled the problem down to a simple program, that...
1
by: dan | last post by:
Hi NG, i have have a strange problem with a Click Event in a custom control. The OnClick method assigned to a Link Button gets invoked, but the method called in that method is ignored. Instead,...
5
by: Simon Verona | last post by:
I have a strange problem with a Windows Forms application. It installs and runs fine on my development machine but consistently comes up with errors on any installed machine. I get an error...
0
by: Marc Robitaille | last post by:
Hello group I have a strange problem. I have a panel. On this panel, I can drop custom Textbox that I create at runtime. I have a toolbar on witch a delete button exist. When I click on this...
1
by: Sosh | last post by:
Hi, I'm pulling my hair out trying to work this out. Pehaps I am missunderstanding something - hopefully someone can shed some light on this: 1) I have a class library that contains a bunch...
7
by: Tim_Mac | last post by:
hi, using .net 2.0, i have a web form with lots of textboxes, drop-down-lists etc. There are lots of required field validators and regular expression validators. When i click the 'save' button,...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
6
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Yesterday Visual Studio gave me a strange error both at compiletime and at designtime that had no obvious connection to anything I had changed recently. After some effort tracking down the problem...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.