Results 1 to 22 of 22

Thread: [RESOLVED] chnaging Textbox Background color

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Resolved [RESOLVED] chnaging Textbox Background color

    Hi there I am having problems changing the backgrounf colour of a mobile textbox at runtime

    This is my code

    Protected Sub oblstRec_ItemSelect(ByVal sender As Object, ByVal e As System.Web.UI.MobileControls.ObjectListSelectEventArgs) Handles oblstRec.ItemSelect
    Me.ActiveForm = frmRes
    lblpartn.Text = e.ListItem.Item("PartNumber")
    txtpartn.Text = e.ListItem.Item("PartName")
    txtcon.Text = e.ListItem.Item("Condition")
    txtloc.Text = e.ListItem.Item("Location")
    txtquan.Text = e.ListItem.Item("Quantity")
    txtval.Text = e.ListItem.Item("Valid")
    If (txtval.Text = 0) Then
    Me.txtval.BackColor = Drawing.Color.Aqua
    Else
    Me.frmRes.BackColor = Drawing.Color.Green
    End If
    End Sub

    It tests if the data reterived for the txtval textbox is 0, if it is it should change the background coloyr to aqua and if not green
    It does nothing, yet if i change the textbox name to the form name it will change the form background with this code just not the text box background
    Anyone have any ideas it is driving me nuts
    lee

  2. #2
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: chnaging Textbox Background color

    Are you playing with its background elsewhere in your code like setting it to white or so? If you place a new textbox out of nowhere on your form and try to change it's background in the same sub, is it working? Is the sub Protected on purpose?
    VB 2005, Win Xp Pro sp2

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: chnaging Textbox Background color

    Hi there thanks for the reply,
    I tried what your said

    TexBox1.BackColor = Color.Aqua

    But there is an error saying that Color is not declared

    The textbox is added at design time and has no color set so it is white
    The text box is poulated from an sql database then the data is check to see if it is 1 or 0 and the color of the text box set to red for 0 or green for one, ther are no errors in my origonal code but the colour is not changed

    hope you can help

    any more information just ask

    lee

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: chnaging Textbox Background color

    your project should already have a project wide imports

    however if you don't for some reason just use the fully qualified name

    System.Drawing.Color.AliceBlue

    or add

    Imports System.Drawing to the top of your code, then you can just use
    color.aliceblue

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: chnaging Textbox Background color

    Hi there thanks for the fast reply

    I did what your said and that fixed the Color error and there are no errors showing but the background still stays white does not change, if i change the form background it works ib the if stsment but not changing the textbox color that does nothing

    any more ideas

    I am using VS 2005 .net 2.0

    lee

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: chnaging Textbox Background color

    can you just try something simple like zen said and just do

    TextBox1.BackColor = Color.AliceBlue

    no if statement.. just see if infact you can change the color of the textbox.

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: chnaging Textbox Background color

    Hi there
    Got rid of the if statment and put it in the main code, still doesnt do anything the textbox remains white background

    Ive scored the internet and apparently this should work

    I am however making a mobile asp.net web site and using vb.net

    so the textbox is a mobile:textbox does this make a difference

    lee

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: chnaging Textbox Background color

    yeah I am sure the fact that it is a mobile control makes all the difference.

    I haven't had the need to ever make a mobile asp.net website yet, however I did notice this comment in the documentation when I skimmed it

    Note The ASP.NET ignores style (Font* and *Color) attributes when rendering to the adapter sets.

    perhaps that has something to do with it?

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: chnaging Textbox Background color

    hi there thanks alot i have read that tooo thats proberbly the problem just need to see if I can get round it some how, not sure how though

    thanks

    lee

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: chnaging Textbox Background color

    Anyone have any ideas this is realy getting to me now
    lee

  11. #11
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: chnaging Textbox Background color

    Quote Originally Posted by lee2006
    Anyone have any ideas this is realy getting to me now
    lee
    Hi,

    You could try something like this;

    VB Code:
    1. <mobile:TextBox
    2.   runat="server"
    3.    id="id"
    4.    Font-Name="fontName"
    5.    Font-Size={NotSet|Normal|Small|Large}
    6.    Font-Bold={NotSet|False|True}
    7.    Font-Italic="{NotSet|False|True}
    8.    ForeColor="foregroundColor"
    9.    BackColor="backgroundColor"
    10.    Alignment={NotSet|Left|Center|Right}
    11.    StyleReference="styleReference"
    12.    Wrapping="{NotSet|Wrap|NoWrap}"
    13.  
    14.    MaxLength="maxLength"
    15.    Numeric="{True, False}"
    16.    Password="{True, False}"
    17.    OnTextChanged="textChangedEventHandler"
    18.    Size="textBoxLength"
    19.    Text="Text"
    20.    InnerText>
    21. </mobile:TextBox>

    Hope it helps,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  12. #12

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: chnaging Textbox Background color

    Hi there thanks that looks like somthing I was just looking at but cant understand where the background color comes from in this line
    BackColor="backgroundColor"
    what is "backgroundColor" and how do i now what color is set

    sorry i may be dimm

    hope u can help

    lee

  13. #13
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: chnaging Textbox Background color

    Quote Originally Posted by lee2006
    Hi there thanks that looks like somthing I was just looking at but cant understand where the background color comes from in this line
    BackColor="backgroundColor"
    what is "backgroundColor" and how do i now what color is set

    sorry i may be dimm

    hope u can help

    lee
    Hi,

    Backgroundcolor means = Color.Red ore the color you wants.

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  14. #14
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: chnaging Textbox Background color

    actually that looks sort of like a markup language... not actual VB. my guess is you would have to use something like a hex color value or a defined name color value, and not the actual color.whatever structure... just like an HTML page.

  15. #15

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: chnaging Textbox Background color

    Hi there Trioed what you said but i need to be able to change the color from the VB code if statment, can see how this would work from the code you gave, if it does or you have any other ideas love to here them

    thanks again

    lee

  16. #16
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: chnaging Textbox Background color

    Quote Originally Posted by lee2006
    Hi there Trioed what you said but i need to be able to change the color from the VB code if statment, can see how this would work from the code you gave, if it does or you have any other ideas love to here them

    thanks again

    lee
    Hi,

    First things first, did my code helped you and could you change the backcolor of your textbox.

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  17. #17

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: chnaging Textbox Background color

    I understand from what you said and I have check that mobile web forms ignore the color element for any component e.g labels, textboxs, panales and so on. Dont know why but it does. The code you gave me, i understand adding the backColor = "backgroundColor" to the asp.net code but i did not understand where and how I assign the color to that variable, in what code and how, never done anything like that before, it has to be possible as manhy mobile apps have colored text areas.

    thanks

    let me know

    lee

  18. #18
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: chnaging Textbox Background color

    I found this note while I was looking around:

    ForeColor, BackColor—These are used to set the foreground and background
    colors for text display on a mobile device, for mobile phone
    development, they are not very useful but because most mobile devices
    are monochrome in nature.

    so that, combined with the note in the MSDN documentation that control styles are ignored when rendering to adapter sets, you may simply just NOT be able to do this without a bunch of custom functionality.

  19. #19
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: chnaging Textbox Background color

    Hi,

    You should read this link about colors and Fonts that you can use into Mobile-Based Pocket PCs;

    http://msdn2.microsoft.com/en-us/library/ms854925.aspx

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  20. #20
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: chnaging Textbox Background color

    man google works quick.. this very thread is already on page 4 when I did a search for this particular topic of chaning an ASP.NET mobile control backcolor.

    http://www.google.com/search?q=asp.n...&start=30&sa=N

  21. #21

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: chnaging Textbox Background color

    Hi there thanks for all your help guess ill have to console my self to it cant be done then, checked out the document that you listed, was a great idea but it changes all the text boxs on all the form not just one and some of the language is not compatible with mobile devices not sure why

    cant belive somthing so simple is so hard to do

    very frustrating

    thanks

    lee

  22. #22

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    40

    Re: chnaging Textbox Background color

    Hi there
    thanks for all your help aprediacte lots
    I set up the application as an asp.net website, removed the default asp.net file then added a mobile web file
    This way it is not specific to any device in perticular will run on pda and phone. Least thats what I have been told.
    Does this help
    lee

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width