Click here to Skip to main content
15,896,259 members
Articles / Web Development / XHTML

Master Pages and JavaScript document.getElementById

Rate me:
Please Sign up or sign in to vote.
4.66/5 (34 votes)
13 Dec 2007CPOL3 min read 284.2K   2.1K   44  
This article talks about the issues faced in accessing controls inside a Master Page from JavaScript, and points a quick solution.
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script language="javascript" src="JScript.js"></script>
    <table>
        <tr>
            <td colspan="2">
                <h2>This is the contentpage</h2>
            </td>            
        </tr>
        <tr>
            <td>
                Fill a text here and click on "Show Text"
            </td>
            <td>
                <asp:TextBox ID="txtTest" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="btnShowText" Text="Show Text" runat="server" OnClientClick="ShowText()" />
            </td>
        </tr>
    </table>
</asp:Content>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Technical Lead
India India
An Electronics Engineer by curricula, Software Engineer by profession. Have passion towards developing applications using Microsoft's .NET technology.

Comments and Discussions