472,353 Members | 1,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

BackColor binding does not work on postback

Hi,

I have the following label markup (label is inside FormView):

<asp:Label
ID="lblIndicatorReady" runat="server" Text="RE" ToolTip="Ready"
BackColor='<%#
Eval("Ready").ToString()=="True"?System.Drawing.Co lor.FromName("#FFFF80"):System.Drawing.Color.White
%>'
Enabled='<%# Eval("Ready") %>'
Font-Bold='<%# Eval("Ready") %>'>
</asp:Label>

I.e. late binding for the "Ready" property used to determine should the
label be
(bold, highighted and enabled) or (plain, white background, disabled)

On initial load everything works as expected (for ready items label is
colored). But on postbacks BackColor is always white for some reason.
Enabled and Bold properties are shown correctly though.

Any ideas?

Dmitry.



Sep 28 '07 #1
6 2800
Hi Dmitry,

As for the ASP.NET Label DataBinding backColor color problem, I have also
performed some tests on my side and did repro the same behavior. Actually,
here is something else I also got:

The problem is not specific to FormView but seems a binding issue of the
Label control. I can get this behavior even through the following simple
routine:

** put a Label on the top level of aspx form
** and use a page variable to perform databinding against the Label control
** After click another posback button, the previous bound color
lost(Forecolor property also suffers this problem)

Currently I'll do some further research on this and will update you if
there is any new finding or information.

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: "Dmitry Duginov" <di**@nospam.nospam>
Subject: BackColor binding does not work on postback
Date: Fri, 28 Sep 2007 10:10:07 -0400
>
Hi,

I have the following label markup (label is inside FormView):

<asp:Label
ID="lblIndicatorReady" runat="server" Text="RE" ToolTip="Ready"
BackColor='<%#
Eval("Ready").ToString()=="True"?System.Drawing.C olor.FromName("#FFFF80"):S
ystem.Drawing.Color.White
>%>'
Enabled='<%# Eval("Ready") %>'
Font-Bold='<%# Eval("Ready") %>'>
</asp:Label>

I.e. late binding for the "Ready" property used to determine should the
label be
(bold, highighted and enabled) or (plain, white background, disabled)

On initial load everything works as expected (for ready items label is
colored). But on postbacks BackColor is always white for some reason.
Enabled and Bold properties are shown correctly though.

Any ideas?

Dmitry.



Oct 1 '07 #2

Hi, Steven!

Anything new? Workarounds, suggestions?

Dmitry

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:WE*************@TK2MSFTNGHUB02.phx.gbl...
The problem is not specific to FormView but seems a binding issue of the
Label control. I can get this behavior even through the following simple
....
Currently I'll do some further research on this and will update you if
there is any new finding or information.
This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
>>From: "Dmitry Duginov" <di**@nospam.nospam>
Subject: BackColor binding does not work on postback
Date: Fri, 28 Sep 2007 10:10:07 -0400
>>
Hi,

I have the following label markup (label is inside FormView):

<asp:Label
ID="lblIndicatorReady" runat="server" Text="RE" ToolTip="Ready"
BackColor='<%#
Eval("Ready").ToString()=="True"?System.Drawing. Color.FromName("#FFFF80"):S
ystem.Drawing.Color.White
>>%>'
Enabled='<%# Eval("Ready") %>'
Font-Bold='<%# Eval("Ready") %>'>
</asp:Label>

I.e. late binding for the "Ready" property used to determine should the
label be
(bold, highighted and enabled) or (plain, white background, disabled)

On initial load everything works as expected (for ready items label is
colored). But on postbacks BackColor is always white for some reason.
Enabled and Bold properties are shown correctly though.

Any ideas?

Dmitry.




Oct 3 '07 #3
Thanks for your followup Dmitry,

I'm still contacting some other ASP.NET engineers on this issue so as to
definitely confirm this issue.

For workarounds, currently what I have got is a possible means through
programmrtically update the TextBox's Color property through "PreRender"
event. The "PreRender" event is the latest event before the control being
rendered. Therefore, you can register this event for the textbox and detect
its value(through Text property) and programmaticlaly set its BackColor(or
other decorate properties...) at that time. e.g.

==============
protected void TextBox1_PreRender(object sender, EventArgs e)
{
TextBox txt = sender as TextBox;

if (txt.Text == ".....")
{
txt.BackColor = Color.Yellow;
}
else
{
txt.BackColor = Color.Maroon;
}
}
==============

In addition, by some futher testing, in some C# web site projects, I found
the problem is not always reproable. Therefore, I also suggest you to test
it in different projects and pages(you can use TextBox on page's top level
or inside a FormView). It would be helpful that if you can give me a
definite steps that can constantly repro the behavior.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Dmitry Duginov" <di**@nospam.nospam>
References: <#o**************@TK2MSFTNGP03.phx.gbl>
<WE*************@TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: BackColor binding does not work on postback
Date: Wed, 3 Oct 2007 16:42:26 -0400
Hi, Steven!

Anything new? Workarounds, suggestions?

Dmitry

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:WE*************@TK2MSFTNGHUB02.phx.gbl...
>The problem is not specific to FormView but seems a binding issue of the
Label control. I can get this behavior even through the following simple
...
>Currently I'll do some further research on this and will update you if
there is any new finding or information.
This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
>>>From: "Dmitry Duginov" <di**@nospam.nospam>
Subject: BackColor binding does not work on postback
Date: Fri, 28 Sep 2007 10:10:07 -0400
>>>
Hi,

I have the following label markup (label is inside FormView):

<asp:Label
ID="lblIndicatorReady" runat="server" Text="RE" ToolTip="Ready"
BackColor='<%#
Eval("Ready").ToString()=="True"?System.Drawing .Color.FromName("#FFFF80")
:S
>ystem.Drawing.Color.White
>>>%>'
Enabled='<%# Eval("Ready") %>'
Font-Bold='<%# Eval("Ready") %>'>
</asp:Label>

I.e. late binding for the "Ready" property used to determine should the
label be
(bold, highighted and enabled) or (plain, white background, disabled)

On initial load everything works as expected (for ready items label is
colored). But on postbacks BackColor is always white for some reason.
Enabled and Bold properties are shown correctly though.

Any ideas?

Dmitry.





Oct 4 '07 #4

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:ep****************@TK2MSFTNGHUB02.phx.gbl...
Thanks for your followup Dmitry,

I'm still contacting some other ASP.NET engineers on this issue so as to
definitely confirm this issue.

For workarounds, currently what I have got is a possible means through
programmrtically update the TextBox's Color property through "PreRender"
event. The "PreRender" event is the latest event before the control being
rendered. Therefore, you can register this event for the textbox and
detect
its value(through Text property) and programmaticlaly set its BackColor(or
other decorate properties...) at that time. e.g.
Sorry, Steven, but

- the issue is with the Label control, not a textbox
- highlighting has nothing to do with the value of its Text property, it is
bound to the property of a business object

Regards,
Dmitry
==============
protected void TextBox1_PreRender(object sender, EventArgs e)
{
TextBox txt = sender as TextBox;

if (txt.Text == ".....")
{
txt.BackColor = Color.Yellow;
}
else
{
txt.BackColor = Color.Maroon;
}
}
==============

In addition, by some futher testing, in some C# web site projects, I found
the problem is not always reproable. Therefore, I also suggest you to test
it in different projects and pages(you can use TextBox on page's top level
or inside a FormView). It would be helpful that if you can give me a
definite steps that can constantly repro the behavior.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
>>From: "Dmitry Duginov" <di**@nospam.nospam>
References: <#o**************@TK2MSFTNGP03.phx.gbl>
<WE*************@TK2MSFTNGHUB02.phx.gbl>
>>Subject: Re: BackColor binding does not work on postback
Date: Wed, 3 Oct 2007 16:42:26 -0400
Hi, Steven!

Anything new? Workarounds, suggestions?

Dmitry

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:WE*************@TK2MSFTNGHUB02.phx.gbl...
>>The problem is not specific to FormView but seems a binding issue of the
Label control. I can get this behavior even through the following simple
...
>>Currently I'll do some further research on this and will update you if
there is any new finding or information.
This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
From: "Dmitry Duginov" <di**@nospam.nospam>
Subject: BackColor binding does not work on postback
Date: Fri, 28 Sep 2007 10:10:07 -0400
Hi,

I have the following label markup (label is inside FormView):

<asp:Label
ID="lblIndicatorReady" runat="server" Text="RE" ToolTip="Ready"
BackColor='<%#
Eval("Ready").ToString()=="True"?System.Drawin g.Color.FromName("#FFFF80")
:S
>>ystem.Drawing.Color.White
%>'
Enabled='<%# Eval("Ready") %>'
Font-Bold='<%# Eval("Ready") %>'>
</asp:Label>

I.e. late binding for the "Ready" property used to determine should the
label be
(bold, highighted and enabled) or (plain, white background, disabled)

On initial load everything works as expected (for ready items label is
colored). But on postbacks BackColor is always white for some reason.
Enabled and Bold properties are shown correctly though.

Any ideas?

Dmitry.







Oct 5 '07 #5

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:g6**************@TK2MSFTNGHUB02.phx.gbl...
Hi Dmitry,

Sorry for keep you waiting.

After some further research, I got the cause of the problem. It is
actually
caused by the "Color.FromName" function you used. In your original code,
you use it as below:

System.Drawing.Color.FromName("#FFFF80")
lost on postback). One quick resolution here(if you do need to specify the
"#xxxxxx" like html color instead of a known color name or RGB value, you
can use the ColorTranslator.FromHtml() method instead. e.g.
Thank you! It resolved the issue.

Dmitry.
Oct 9 '07 #6
You're welcome!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Dmitry Duginov" <di**@nospam.nospam>
References: <#o**************@TK2MSFTNGP03.phx.gbl>
<WE*************@TK2MSFTNGHUB02.phx.gbl<eo0no3fBIH A.91
>Subject: Re: BackColor binding does not work on postback
Date: Tue, 9 Oct 2007 17:00:56 -0400
>

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:g6**************@TK2MSFTNGHUB02.phx.gbl...
>Hi Dmitry,

Sorry for keep you waiting.

After some further research, I got the cause of the problem. It is
actually
caused by the "Color.FromName" function you used. In your original code,
you use it as below:

System.Drawing.Color.FromName("#FFFF80")
>lost on postback). One quick resolution here(if you do need to specify
the
>"#xxxxxx" like html color instead of a known color name or RGB value, you
can use the ColorTranslator.FromHtml() method instead. e.g.

Thank you! It resolved the issue.

Dmitry.
Oct 10 '07 #7

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

Similar topics

1
by: Sparhawk | last post by:
I ran into troubles binding my repeater controls in Page_PreRender. The problem is that the Repeater_ItemCommand does not fire if the control is...
6
by: LU | last post by:
A)I build a datagrid based on a calendar date selection. B)When user clicks a button column on the datagrid I want to highlight this row. I use...
4
by: Alan Silver | last post by:
Hello, I'm trying to use an ArrayList to do data binding, but am getting an error I don't understand. I posted this in another thread, but that...
1
by: Firewalker | last post by:
I am attempting to change the backColor property on the previously instantiated buttons FROM a listbox_doubleClick event. I thought it would be...
0
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%#...
6
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure...
8
by: AG | last post by:
ASP.NET 2.0, VS 2005 I have a gridview with paging enabled, bound to an objectdatasource. Both were dropped on to the page and configured via the...
1
by: bogdan | last post by:
I need to execute some code _after_ page controls are bound to data (e.g. DropDownList). I could probably handle DataBound events for each control....
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.