Saturday, March 12, 2011

How To Find Controls Inside MasterPage ContentPlaceHolder Of ASP.Net Page

1 comments 3/12/2011
Sign up to receive our site updates!
I experienced Page.FindControl() is not working in Asp.Net Page when we are using MastePage.

In this Article i am going to show how to find controls in Asp.Net Page as well How to get MaterPage controls in Asp.net Page

How To Find Controls Of MastePage In Asp.Net Page

»In MasterPage i added a label and One ContentPlaceHolder, This is My MasterPage code snippet to demonstrate

<form id="form1" runat="server"&gt
   <div><asp:Label ID="lblUN" runat="server" Text="Raji">asp:Label>div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
      asp:ContentPlaceHolder>
</form>
»I added a TextBox inside ContentPlaceHolder of Asp.Net page that uses a master Page.
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server" >

    <asp:TextBox ID="txtUName" runat="server" Text="Raji">asp:TextBox>
   
&lt/asp:Content>



»To find the 'Label' controls of Master page just add the following line in CodeBehind(.cs) page

Label l = Master.FindControl("lblUN") as Label;

How To Find The Controls In a Page

»To find the controls in page just use the following code snippet
TextBox TB= Master.FindControl("ContentPlaceHolder1").FindControl("txtUName") as TextBox;

Happy Coding
Your Ad Here

1 comments:

Anonymous said... [Reply]

Thanks alot....

Respects for your's Questions & Opinions

  • Friends
  •  

    Recent Posts

    New Comments

    Copyright 2008 All Rights Reserved Tech Tasks Template by Rajesh Kumar Chekuri

    Share
    Me
    Twitter Facebook Google +1 Pinterest Delicious Digg Stumbleupon More

    Connect to TT Facebook Google +1
    Back to Top