viperbyte
07-10-2011, 07:29 PM
Hello everyone. I'm super stuck. I'm trying to set the value of a label on a default.aspx page with some jquery code and it's not happenng. No errors, just not happening. Below is my attempt at it. I'm trying to set lblWarning. Can someone please show me how to do this?
$(document).ready(function() {
var MaxLength = 10;
var result;
$('#txtBarCode').keypress(function(e) {
if ($(this).val().length >= MaxLength) {
//ShowBarCode();
result = ShowBarCode();
document.getElementById("lblWarning").value = result;
}
});
});
function ShowBarCode() {
$.ajax({
type: "POST",
url: "Default.aspx/RetreiveBarCode",
data: '{barcode: "' + $("#<%=txtBarCode.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: alert('success'),
failure: function(response) {
alert('failure');
}
});
}
This is the RetreiveBarCode function in the code behind file.
Public Shared Function RetreiveBarCode(ByVal barcode As Integer) As String 'List(Of testTbl)
Dim con = ConfigurationManager.ConnectionStrings("CONNSTRING").ConnectionString
Dim ListOfContacts As List(Of testTbl)
Dim contactsObj As New ContactActionLayer.ContactActionDAL
Dim theValue As Integer = Nothing
theValue = barcode
contactsObj.OpenConnection(con)
ListOfContacts = contactsObj.RetreiveTestTbl(theValue)
contactsObj.CloseConnection()
Return ListOfContacts(0).Description
End Function
$(document).ready(function() {
var MaxLength = 10;
var result;
$('#txtBarCode').keypress(function(e) {
if ($(this).val().length >= MaxLength) {
//ShowBarCode();
result = ShowBarCode();
document.getElementById("lblWarning").value = result;
}
});
});
function ShowBarCode() {
$.ajax({
type: "POST",
url: "Default.aspx/RetreiveBarCode",
data: '{barcode: "' + $("#<%=txtBarCode.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: alert('success'),
failure: function(response) {
alert('failure');
}
});
}
This is the RetreiveBarCode function in the code behind file.
Public Shared Function RetreiveBarCode(ByVal barcode As Integer) As String 'List(Of testTbl)
Dim con = ConfigurationManager.ConnectionStrings("CONNSTRING").ConnectionString
Dim ListOfContacts As List(Of testTbl)
Dim contactsObj As New ContactActionLayer.ContactActionDAL
Dim theValue As Integer = Nothing
theValue = barcode
contactsObj.OpenConnection(con)
ListOfContacts = contactsObj.RetreiveTestTbl(theValue)
contactsObj.CloseConnection()
Return ListOfContacts(0).Description
End Function