Hola,
Tengo el siguiente codigo en un aspx:
Código aspx:
Ver original<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Ajax.aspx.vb" Inherits="AJAX1.Ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>AJAX</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextNombreBuscar" runat="server" aling="Left" Width="250px"></asp:TextBox>
[B]<input id="btnBuscar" type="button" value="Resultado" onclick="Ajax.obtener_operarios(TextNombreBuscar.value,obtener_operarios_CallBack)" />[/B]<br>
</div>
<div id="txtResultado" Width="100px" />
</div>
</form>
<script type="text/javascript">
function obtener_operarios_CallBack(response) {
alert("entra");
if (response.error != null) {
alert("Se presentó un error ");
return;
}
target = "txtResultado";
document.getElementById(target).innerHTML = response.value;
}
</script>
y el siguiente código en el .aspx.vb:
Código vb.net:
Ver originalPublic Class Ajax
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Register Ajax.NET methods from this class
AjaxPro.Utility.RegisterTypeForAjax(GetType(Ajax))
End Sub
<AjaxPro.AjaxMethod()> _
Public Function obtener_operarios(ByVal nombre As String) As String
Dim conn As New MySqlConnection
Dim nombreBuscar As String
[B
]nombreBuscar
= UCase(Request
.QueryString("nombre"))[/B
] conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("conexionMySQL").ConnectionString
Dim mysql_comando As New MySqlCommand("select distinct noperario, operario from cdp_operaciones where operario like '%" & nombreBuscar & "%'order by operario asc", conn)
Dim reader As MySqlDataReader
Dim da As New MySqlDataAdapter(mysql_comando)
Dim objRow As New TableRow()
Dim numoperario, nombreoperario As String
Try
Using conn
'se abre la conexion
conn.Open()
With mysql_comando
reader = .ExecuteReader()
Dim j As Integer = 1
While reader.Read()
numoperario = reader.GetValue(0)
nombreoperario = reader.GetValue(1)
End While
.Dispose()
End With
End Using
Return (numoperario + nombreoperario)
Catch ex As Exception
Return "0"
Finally
conn.Dispose()
End Try
Me.TextNombreBuscar.Text = ""
End Function
End Class
Lo que quiero es, cuando se le de al botón "btnBuscar" que vaya a la función "obtener_operarios" y recoger el contenido del "TextNombreBuscar" . Lo estoy haciendo de esta manera:
Código aspx:
Ver original<input id="btnBuscar" type="button" value="Resultado" onclick="Ajax.obtener_operarios(TextNombreBuscar.value,obtener_operarios_CallBack)" />
Código vb.net:
Ver originalDim nombreBuscar As String
nombreBuscar
= UCase(Request
.QueryString("nombre"))
Pero no me coge el valor del TextNombreBuscar.
Alguilen me puede echar una mano?