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

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

Let’s Check the Output First:

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

        <div class="main">
            <asp:Label ID="lblMaster" runat="server" Text="Master Label"></asp:Label>
            <asp:TextBox ID="txtMaster" runat="server"></asp:TextBox>
            <hr />

            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>

Add the Asp Button Under Content Page:

<asp:Button ID="cmdChild" OnClientClick="return GetMasterValue();" runat="server" Text="Read Master TexBox Value" />

Now add the Javascript Function in Content Page:

<script type="text/javascript">
    function GetMasterValue() {
        alert(document.getElementById('<%=Master.FindControl("txtMaster").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