BackColor binding does not work on postback

Discussion in 'ASP .Net' started by Dmitry Duginov, Sep 28, 2007.

  1. 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"):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.
     
    Dmitry Duginov, Sep 28, 2007
    #1
    1. Advertising

  2. 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/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: "Dmitry Duginov" <>
    >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.
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
     
    Steven Cheng[MSFT], Oct 1, 2007
    #2
    1. Advertising

  3. Hi, Steven!

    Anything new? Workarounds, suggestions?

    Dmitry

    "Steven Cheng[MSFT]" <> wrote in message
    news:...

    > 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" <>
    >>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.
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>

    >
     
    Dmitry Duginov, Oct 3, 2007
    #3
  4. 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" <>
    >References: <#>

    <>
    >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]" <> wrote in message
    >news:...
    >
    >> 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" <>
    >>>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.
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>

    >>

    >
    >
    >
     
    Steven Cheng[MSFT], Oct 4, 2007
    #4
  5. "Steven Cheng[MSFT]" <> wrote in message
    news:ep9%...
    > 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" <>
    >>References: <#>

    > <>
    >>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]" <> wrote in message
    >>news:...
    >>
    >>> 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" <>
    >>>>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.
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>

    >>
    >>
    >>

    >
     
    Dmitry Duginov, Oct 5, 2007
    #5
  6. 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")

    this is actually an incorrect and unsupported usage. Refer to the document
    below:

    #Color.FromName Method
    http://msdn2.microsoft.com/en-us/library/system.drawing.color.fromname.aspx

    >>>>>>picked from the doc>>>>>

    Parameters
    name
    A string that is the name of a predefined color. Valid names are the same
    as the names of the elements of the KnownColor enumeration.
    <<<<<<<<<<<<<

    Therefore, if you use the "#XXXXXX" like color, it will cause the problem
    when serializing the viewstate. The color is unknown to the serializer and
    it store the blank color into the view state(that's why you see the color
    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.

    ==================
    <asp:Label ID="Label1" runat="server" Text="Label"
    BackColor='<%#
    TestBool.ToString()=="True"?System.Drawing.ColorTranslator.FromHtml("#FFFF80
    ") ystem.Drawing.Color.White %>' ........./>

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

    I've tested it and it works. Hope this helps.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


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


    --------------------
    >From: "Dmitry Duginov" <>
    >Subject: Re: BackColor binding does not work on postback
    >Date: Thu, 4 Oct 2007 19:56:54 -0400


    >
    >
    >"Steven Cheng[MSFT]" <> wrote in message
    >news:ep9%...
    >> 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" <>
    >>>References: <#>

    >> <>
    >>>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]" <> wrote in message
    >>>news:...
    >>>
    >>>> 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" <>
    >>>>>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.
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>
    >>>
    >>>
    >>>

    >>

    >
    >
    >
     
    Steven Cheng[MSFT], Oct 8, 2007
    #6
  7. "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > 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.
     
    Dmitry Duginov, Oct 9, 2007
    #7
  8. 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" <>
    >References: <#>

    <> <eo0no3fBIHA.91
    >Subject: Re: BackColor binding does not work on postback
    >Date: Tue, 9 Oct 2007 17:00:56 -0400


    >
    >
    >"Steven Cheng[MSFT]" <> wrote in message
    >news:...
    >> 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.
    >
    >
    >
     
    Steven Cheng[MSFT], Oct 10, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    3
    Views:
    515
    MWells
    Jan 26, 2005
  2. =?Utf-8?B?U3RldmUgRm9yZA==?=

    BackColor attribute in HyperLink doesn't work in Firefox

    =?Utf-8?B?U3RldmUgRm9yZA==?=, Oct 7, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    566
    =?Utf-8?B?U3RldmUgRm9yZA==?=
    Oct 10, 2005
  3. jobs
    Replies:
    1
    Views:
    2,372
  4. Goran Djuranovic

    Button BackColor not working on PocketPC

    Goran Djuranovic, Jun 25, 2004, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    128
    Goran Djuranovic
    Jun 25, 2004
  5. Replies:
    1
    Views:
    873
    Alessandro Zifiglio
    Jul 20, 2006
Loading...

Share This Page