Click here to Skip to main content
15,891,762 members
Articles / Web Development / ASP.NET

jQuery introduction and how to use jQuery with ASP.NET Master page and simple pages

Rate me:
Please Sign up or sign in to vote.
4.69/5 (37 votes)
22 Jan 2013CPOL3 min read 414.8K   8.1K   34  
How to access elements of a master page in jQuery.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">

    $(document).ready(function () {

//    Solution 1:
        $('input[id$=TextBox1]').keyup(function () {
            //write your code here

            var txt = $('input[id$=TextBox1]').val();
            $('input[id$=TextBox2]').val(txt);
        });


        //    Solution 2:
        var lbltext = $('#' + '<%=lbl.ClientID %>').text();

        $('#' + '<%=TextBox4.ClientID %>').val(lbltext);

    });


//    Solution 3:

    $(document).ready(function () {


        
        alert($("[id$=_TextBox6]").attr("id"));

     
    }); 
   
  
    




    

</script>


</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
  
  <p> Solution 1 :</p>
   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
   <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

  <p> Solution 2:</p> 
   <asp:Label ID="lbl" runat="server" Text="CopytoTextbox"></asp:Label>
   <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>


   <p> Solution 3 : get id of textbox6</p>
     
   <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>

   


   
</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
Software Developer
India India
I do believe life is to help others ... So here i am .. in my spare time i learn new things of programming and try to help people with my knowledge .
I'm an energetic, self-motivated and hard-working Developer and Information Technology Professional with experience in projects, website design and development.

Visit My Technical Blog

Comments and Discussions