Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
me have a repeater which have labels and textboxes i want to access these controls values through ajax me have code which give insted of values Undefine my code are below
C#
<script type="text/javascript">
    function AddItemToCart() {
        var itemId = $('[id$="lblBookName"]').val();
        var itemName = $('[id$="lblPrice"]').val();       
        var itemPrice = $("#txtimg").val();     

        $.ajax({
            type: "POST",
            traditional: true,
            url: "repeater.aspx/AddItemToCart",
            data: "{'Id':'" + itemId + "','Name':'" + itemName + "','Price':'" + itemPrice + "'}",
            contentType: "Application/json; charset=utf-8",
            datatype: "json",
            success: function (data) {              
                $('#tblData').Html(data.d);                          

            },
        });
    }
i use these values in table which showes insted of values shows Undefine..
XML
and this is the repeater control i think i not access these contols properly but me not any idea how to access these in ajax funtion.
<asp:Label ID="lblBookName" runat="server" Text='<%# Bind("ItemName") %>'></asp:Label>
<asp:Label ID="lblCity" runat="server" Text=' <%# Bind("ItemQuantity") %>'></asp:Label>
<asp:TextBox ID="txtimg" runat="server" Text='<%# Bind("ItemImage") %>'></asp:TextBox>
Posted
Updated 23-Apr-14 23:24pm
v3
Comments
Murugesan22 24-Apr-14 10:11am    
when you want the data if any click event in repeater like clicktoadd in row

i have code with click event for every row its ok
then i will post
Mian Sahib Jan 24-Apr-14 11:17am    
it have itemcommand property any way sir plz post yours code may be i take some idea from that

1 solution

You should try like this.

var itemId = $('#<%=lblBookName.ClientID%>').val();
var itemName = $('#<%=lblPrice.ClientID%>').val();
var itemPrice =$('#<%=txtimg.ClientID%>').val();

hope it helps :)
 
Share this answer
 
Comments
Mian Sahib Jan 24-Apr-14 7:20am    
but now this show the error
control not found in current context.the above control which me mention actualy it present inside the repeater. like this
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" >
<itemtemplate>
<asp:Label ID="lblBookName" runat="server" Text='<%# Bind("ItemName") %>'>
Sanket Saxena 24-Apr-14 7:36am    
If you are using .Net 4.0 I would recomment ClientIDMode="Predictable" to generat ID's which are easy to use with javascript.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900