Results 1 to 8 of 8

Thread: Code behind variable in html control attribute problem

  1. #1

    Thread Starter
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Code behind variable in html control attribute problem

    I have a boolean in my code behind that I want to control the visibility of a control but I get a databinding error. Not sure if my syntax is correct.
    I've simplified what I am doing below. I have no problem accessing public and protected variables in html via <%=whatever%> but when I try to apply to a control attribute it isn't working.


    VB Code:
    1. Protected myBoolean as boolean=false
    2.  
    3. <html>
    4. <Component:myComponent Visible="<%# myBoolean%>"/>
    5. </html>
    Truly, you have a dizzying intellect.

  2. #2
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Re: Code behind variable in html control attribute problem

    I'll take a shot at this. I think the reason might be that the control wants a string, not a boolean value.

    Try doing this:

    Code:
    Protected myBoolean as String = "false"
    
    <html>
    <Component:myComponent Visible="<%= myBoolean%>"/>
    </html>
    Let me know!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  3. #3

    Thread Starter
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Code behind variable in html control attribute problem

    Tried that one to
    Error is:
    <%=myBoolean%> is not a valid value for Boolean
    Truly, you have a dizzying intellect.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Code behind variable in html control attribute problem

    Me.MyControl.Visible = myBoolean

  5. #5

    Thread Starter
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Code behind variable in html control attribute problem

    Where are talking the HTML side of things
    Truly, you have a dizzying intellect.

  6. #6
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Re: Code behind variable in html control attribute problem

    I would do it in the codebehind, but you could try this:

    <html>
    <Component:myComponent Visible="<%= myBoolean.toString %>"/>
    </html>

    No idea if this works, never do it this way.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Code behind variable in html control attribute problem

    Quote Originally Posted by gtilles
    Where are talking the HTML side of things
    What I've shown is the same thing, only it's the proper way to facilitate separation of UI and UI logic.

  8. #8

    Thread Starter
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Code behind variable in html control attribute problem

    Thanks but....my question was doing it on the HTMl side not how to do it on the code behind. I am already aware of how to do it on the code-behind.....but in this case, proper coding or not...I want it on the HTML.
    This is the question. not looking for alternate answers.
    Truly, you have a dizzying intellect.

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