如何通过ajax访问转发器控件值 [英] how to access repeater controls values through ajax

查看:89
本文介绍了如何通过ajax访问转发器控件值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个转发器,它有标签和文本框我想通过ajax访问这些控件值我有代码,它给出了值的定义Undefine我的代码在下面

 < 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
成功:函数(数据){
$(' #tblData')。Html(data.d);

},
});
}

我在表格中使用这些值,显示值的显示Undefine ..

这是转发器控件我认为我没有正确访问这些控件但我不知道如何在ajax功能中访问这些。 
< asp:标签 ID = lblBookName runat = 服务器 文字 =' <% #Bind( < span class =code-string> ItemName%> ' > < / asp:Label >
< asp:Label ID = lblCity runat = server 文本 =' <% #Bind( ItemQuantity%> ' > < / asp:Label >
< asp:TextBox < span class =code-attribute> ID = txtimg runat = 服务器 正文 =' <% #Bind( ItemImage%> ' > < / asp:TextBox >

解决方案

' [id


=lblBookName]')。val();
var itemName =


' [ID

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

<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..

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>

解决方案

('[id


="lblBookName"]').val(); var itemName =


('[id


这篇关于如何通过ajax访问转发器控件值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆