code within control declaration

Discussion in 'ASP .Net' started by Daves, Apr 11, 2005.

  1. Daves

    Daves Guest

    I'd like to have a control visible/not visible based on some value eg:
    <asp:Button ID="Button1" runat="server" Text="Change" Visible=<%
    Membership.GetUser("david").IsOnline >% />

    doesn't seem to work, do I maybe have to set the Visible property from
    codebehind?
    Daves, Apr 11, 2005
    #1
    1. Advertising

  2. Daves

    Karl Seguin Guest

    Daves:

    (a) you COULD use <%= instead of just <% which would solve your problem
    (b) you SHOULD use codebehind because it's far easier to read/maintain...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "Daves" <> wrote in message
    news:...
    > I'd like to have a control visible/not visible based on some value eg:
    > <asp:Button ID="Button1" runat="server" Text="Change" Visible=<%
    > Membership.GetUser("david").IsOnline >% />
    >
    > doesn't seem to work, do I maybe have to set the Visible property from
    > codebehind?
    >
    >
    Karl Seguin, Apr 11, 2005
    #2
    1. Advertising

  3. On Mon, 11 Apr 2005 12:51:02 -0500, Daves <> wrote:

    > I'd like to have a control visible/not visible based on some value eg:
    > <asp:Button ID="Button1" runat="server" Text="Change" Visible=<%
    > Membership.GetUser("david").IsOnline >% />
    >
    > doesn't seem to work, do I maybe have to set the Visible property from
    > codebehind?
    >
    >


    Looks like a few typos, I assume you're trying to databind here; Visible
    attribute should look like:

    Visible='<%# Membership.GetUser("david").IsOnline %>'

    and make sure you call .DataBind() on the textbox at the appropriate
    time...

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
    Craig Deelsnyder, Apr 11, 2005
    #3
    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. Noah
    Replies:
    5
    Views:
    947
  2. Alex Vinokur
    Replies:
    4
    Views:
    573
    Jonathan Turkanis
    Apr 5, 2004
  3. Ovidesvideo
    Replies:
    4
    Views:
    483
    Andrey Tarasevich
    Dec 10, 2004
  4. kelvSYC
    Replies:
    6
    Views:
    7,213
    Richard Herring
    May 17, 2005
  5. Replies:
    4
    Views:
    1,051
    Richard Tobin
    Dec 12, 2006
Loading...

Share This Page