Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9211089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:13:01+00:00 2026-06-18T01:13:01+00:00

I have the following code: <asp:LinkButton runat=server CommandName=SwitchStep CommandArgument='<%# DataBinder.Eval(Container.DataItem, ID)%>’ CssClass=<%# some conditional

  • 0

I have the following code:

<asp:LinkButton runat="server" 
                CommandName="SwitchStep"
                CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID")%>'
                CssClass="<%# some conditional code here %> activestep">
    Step <%# Container.ItemIndex + 1 %>: <%# DataBinder.Eval(Container.DataItem, "ID")%>
</asp:LinkButton>

Inline statements work in the CommandArgument attribute, and I know they work in the text attribute. For some reason, though, in the CssClass attribute, the inline statement ends up (unparsed) in the HTML output! What the hell?

In Chrome:

<a class="&lt;%= 'steptab' %&gt;" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("StepControl:_ctl1:_ctl0", "", true, "", "", false, true))'>
            Step 1: section_name</a>

Has anyone run into this before? I’m not sure why this shouldn’t work. It doesn’t seem logical, and I’m a little frustrated.

Some notes:

  • If I put a character in here that doesn’t belong, such as “?” (this is VB), the compiler complains.
  • Any server tag (<%, <%#, etc) shows up in the HTML.
  • This is inside a repeater control. Wait, that’s in the code.
  • If I remove the “activestep” class after the inline statement, the inline statement still appears, although at one time I didn’t have a class attribute appearing in HTML at all.

Any ideas? Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:13:02+00:00Added an answer on June 18, 2026 at 1:13 am

    I am not sure if you can write an Expression in CssClass property. Try this:

    <asp:LinkButton runat="server" 
                    CommandName="SwitchStep"
                    CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ID")%>'
                    CssClass="<%$ Iif(condition, "activestep", "") %>">
        Step <%# Container.ItemIndex + 1 %>: <%# DataBinder.Eval(Container.DataItem, "ID")%>
    </asp:LinkButton>
    

    On the other hand, you could use ItemDataBound event handler to wrapper your condition and set the CssClass property on the control inside your Repeater. Take a look

    In the WEbForm, add a reference to the ItemDataBound

    <asp:Repeater id="Repeater1" OnItemDataBound="Repeater1_ItemDataBound" runat="server">
    ...
    </asp:Repeater>
    

    VB.NET

    ' This event is raised for the header, the footer, separators, and items.
    Public Sub Repeater1_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) 
    
        ' Execute the following logic for Items and Alternating Items.
        if e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
    
            Dim p as Product = CType(e.Item.DataItem, Product) ' cast to your entity just a sample
    
            If p.Active Then ' check some condition     
    
                CType(e.Item.FindControl("Your_LinkButtonId"), LinkButton).CssClass = "activestep"
    
            End If
        End if
    
    End Sub
    

    C#

    // This event is raised for the header, the footer, separators, and items.
    public void Repeater1_ItemDataBound(Object sender, RepeaterItemEventArgs e) 
    {
        // Execute the following logic for Items and Alternating Items.
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
        {
            Product p = (Product)e.Item.DataItem; // cast to your entity just a sample
    
            if (p.Active) // check some condition
            {
                ((LinkButton)e.Item.FindControl("Your_LinkButtonId")).CssClass = "activestep";
            }
        }  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following itemTemplate in my datalist <ItemTemplate> <asp:LinkButton ID=LinkButton1 CommandName=Select autopostback=True runat=server>'<%#
I have following code: <asp:Button ID=InsertButton runat=server CausesValidation=True CommandName=Insert Text=Add Form PostBackUrl=~/APPLICATION/FormView.aspx?postquestion=/> I using
I have the following ASP code: <asp:LinkButton ID=LinkButton1 runat=server Text=edit item onclick='AddItem.aspx?catid=<%# Eval(CollectionID)%>' />
I have the following code in a ASP.NET master page: <div id=hyperlinkimage><asp:HyperLink ID=SomeHyperLink runat=Server
I have the following code in the front end <asp:Content ID=Content1 ContentPlaceHolderID=cphMain runat=server> <script
I have the following code: <telerik:RadAjaxPanel ID=RadAjaxPanel1 runat=server LoadingPanelID=rlpMain> <asp:ImageButton ID=ImageButton1 runat=server OnClientClick=return confirm('Are
I have the following code <table cellpadding=2 cellspacing=2> <tr> <td>Factory:</td> <td> <asp:TextBox ID=txtFactory runat=server
I have the following aspx code; <asp:GridView ID=GridView1 runat=server AllowPaging=True AllowSorting=True AutoGenerateColumns=False DataKeyNames=ProductId DataSourceID=edsinventory
We have the following code in an UpdatePanel. <asp:UpdatePanel ID=UpdatePanelSearch runat=server UpdateMode=Conditional> <ContentTemplate> <p>Parent
I have the following code <asp:Content ID=headContent ContentPlaceHolderID=head runat=Server> </asp:Content> <asp:Content ID=Content1 ContentPlaceHolderID=ContentPlaceHolder1 runat=Server>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.