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

  • SEARCH
  • Home
  • 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 4624900
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:11:44+00:00 2026-05-22T03:11:44+00:00

I am using Visual Studio 2008 with .NET Framework 3.5. I have a DataGrid

  • 0

I am using Visual Studio 2008 with .NET Framework 3.5. I have a DataGrid with a LinkButton inside a TemplateColumn. I am trying to figure out how to disable the ability to click the LinkButton once it has been clicked. My DataGrid has 6 columns with the LinkButton column displaying years and the others displaying year end data for those years. When a year is clicked the DataGrid displays a breakdown of that year’s data on a month by month basis. When the DataGrid is displaying the month by month breakdown I still need the year column to be visible but without the ability to click. I also have a button and a chart that, by default Visibility is set to false, but after a year is selected the Visibility is set to true with the button giving the ability to close out of the month by month breakdown and return to the year end breakdown. I have everything working except the disabling of the LinkButton.

Here is the code for my DataGrid’s TemplateColumn:

<asp:TemplateColumn HeaderText="Year End">
    <ItemTemplate>
        <asp:LinkButton runat="server" ID="lbYear" Text='<%# DataBinder.Eval(Container, "DataItem.year") %>'></asp:LinkButton>
    </ItemTemplate>
</asp:TemplateColumn>

I have tried the following:

Attempt 1 using code behind:

protected void Page_Load(object sender, EventArgs e)
{
    LinkButton lb = ((LinkButton) FindControl("lbYear"));
    lb.Attributes.Add("onClick", "return false;");
}

Attempt 2 using Javascript:

function disableLinkButton() {
    var lb = document.getElementById("lbYear");
    if (lb.disabled != true) { lb.disabled = true; return true; }
    }
    else { return false; }
}

<asp:TemplateColumn HeaderText="Year End">
    <ItemTemplate>
        <asp:LinkButton runat="server" ID="lbYear" OnClientClick="disableLinkButton()" Text='<%# DataBinder.Eval(Container, "DataItem.year") %>'></asp:LinkButton>
    </ItemTemplate>
</asp:TemplateColumn>

— The 3rd attempt was close which did gray out the LinkButtons but did not disable the ability to click them
Attempt 3 using the ‘Enabled’ property:

<asp:TemplateColumn HeaderText="Year End">
    <ItemTemplate>
        <asp:LinkButton runat="server" ID="lbYear" Enabled='<%# Convert.ToInt32(DataBinder.Eval(Container.DataItem, "year"))==1?Convert.ToBoolean("True"):Convert.ToBoolean("False") %>' Text='<%# DataBinder.Eval(Container, "DataItem.year") %>'></asp:LinkButton>
    </ItemTemplate>
</asp:TemplateColumn>

Some other thoughts I have include using an ‘OnClick’ event or a ‘CommandArgument’. I tried using ‘OnClick’ and in the code behind simply using:

LinkButton lb = ((LinkButton) FindControl("lbYear");
lb.Enabled = false;

Any help, thoughts, ideas, examples, etc. would be greatly appreciated. Thank you all in advance!

Adjusted Code:

<ItemTemplate>
    <asp:LinkButton ID="lbYear" runat="server" OnClick="testClick" Text='<%# DataBinder.Eval(Container, "DataItem.year") %>'></asp:LinkButton>
    <a id="MyContrl_lbYear" href="javascript:__doPostBack('MyContrl$lbYear','')" onclick="this.href='#';this.disabled=true;__doPostBack('MyContrl$lbYear','');"></a>
</ItemTemplate>

protected void showChart(object sender, EventArgs e)
{
    LinkButton lbYear = ((LinkButton)FindControl("lbYear"));
    lbYear.Attributes.Add("onclick", "this.href='#';this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(lbYear, "").ToString());
}
  • 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-05-22T03:11:45+00:00Added an answer on May 22, 2026 at 3:11 am

    Polity, thank you very much for your help, I really appreciate it. I found a different way to go about fixing this issue though.

    .ASPX Code:

    <TemplateColumn>
        <ItemTemplate>
            <asp:LinkButton runat="server" OnClick="test" Text='<%# DataBinder.Eval(Container, "DataItem.year") %></asp:LinkButton>
        </ItemTemplate>
    </TemplateColumn>
    

    .ASPX.CS Code:

    protected void test(object sender, EventArgs e)
    {
        foreach(var y in myDataGrid.Items)
        {
            LinkButton lb = ((y as TableRow).Cells[1].Controls[1] as LinkButton);
            lb.Enabled = false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a C++ extension for python using swig. I've followed the
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
If I write a python script using only python standard libraries, using Python 2.6
Has anyone got EclipseLink MOXy (I'm using eclipselink 2.1.0) to work with Java 5?
I am attempting to pull some information from my tnsnames file using regex. I
I have a script that appends some rows to a table. One of the
We manage a site for a medical charity. They have a number of links
Let say I have the following desire, to simplify the IConvertible's to allow me
This is beyond both making sense and my control. That being said here is
I know its probably possible, but is it practical and doable to try and

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.