Javascript FindControl to get or read Content Page Controls Content data from Asp.Net Master Page C# VB.Net

In many forums i found that c# developers ask expert how to read or access Content page controls data from Master page using clientside javascript FindControl method. Thats why in this javascript tutorial i will explain how you can read or access Content Page content data from Master page by client side javascript function.

Let’s Check the Output First:

To do the example First Add below Controls under Content Page:

<asp:Label ID="lblChild" runat="server" Text="Child Label"></asp:Label>
<asp:TextBox ID="txtChild" runat="server"></asp:TextBox>

Add the Asp Button Under Master Page:

        <div class="main">

            <asp:Button ID="cmdChild" OnClientClick="return GetContentValue();" runat="server" Text="Read Content TexBox Value" />
            <hr />
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>

Now add the Javascript Function in Master Page Head Section:

    <script type="text/javascript">
        function GetContentValue() {
            alert(document.getElementById('<%= MainContent.FindControl("txtChild").ClientID %>').value);
            return false;

Everything completed. You can read any serverside control like dropdownlist, checkbox, radiobutton, checkboxlist, radiobuttonlist etc. as well, using the above javascript method with slight modification.

Download Code Example C#        Download Code Example VB.Net

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code