Click here to Skip to main content
11,801,910 members (54,483 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET Masterpage
I am trying to disable a linkbutton in side data repeater in masterpage from another page. I am trying to create list of pages in masterpage, when one of the link is clicked, it redirects user to that page. So, when the user in the page, its respective link should be disabled, which is in master page. Here are my codes:

Master page:

<asp:ContentPlaceHolder ID="CategoryMenuHolder" runat="server">
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"
                <li class="menus">
                    <asp:LinkButton ID="lnkcategory" runat="server" OnCommand="LinkButton_Command" CommandArgument='<%# Eval("catid") %>'
                        Text='<%# Eval("catname") %>' CommandName="Show" ForeColor="White"></asp:LinkButton>
content page
ContentPlaceHolder holder = (ContentPlaceHolder)Master.FindControl("CategoryMenuHolder");
        Repeater rep = (Repeater)holder.FindControl("Repeater1");
but the repeater comes in as null!
How do I do this?
Thanks in advance Smile | :)
Posted 4-Jan-12 0:43am
Edited 4-Jan-12 11:33am
Nicholas Butler at 4-Jan-12 7:08am
Repeater is a server-side control - it is not itself rendered in the HTML, just it's contents
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Write following in click event of LinkButton
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

first fine the repeater resides in the master page, to get the reference of repeater control use following code
Repeater rpt = (Repeater)Master.FindControl("Repeater1");
to get the object of LinkButton that resides in Repeater item use bellow code
foreach (ListViewItem li in rpt.Items)
           //Finds LinkButton button from Repeater
            LinkButton lkb=(LinkButton) li.FindControl("lnkcategory");
           //Disable LinkButton
            lkb.Enabled = false;
I above code will be helpful to you, if this solution comes helpful to you please give rank to me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 445
1 KrunalRohit 301
2 F-ES Sitecore 215
3 CHill60 185
4 Afzaal Ahmad Zeeshan 180
0 OriginalGriff 2,715
1 Maciej Los 1,900
2 KrunalRohit 1,797
3 CPallini 1,550
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100