Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/04/2013, 02:26
maialenlopez
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años
Puntos: 7
Pregunta Recoger valor de texto escrito en un textbox al clicar en un boton

Hola,

Tengo el siguiente codigo en un aspx:
Código aspx:
Ver original
  1. <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Ajax.aspx.vb" Inherits="AJAX1.Ajax" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7.     <title>AJAX</title>
  8. </head>
  9. <body>
  10.     <form id="form1" runat="server">
  11.         <div>
  12.             <asp:TextBox ID="TextNombreBuscar" runat="server" aling="Left" Width="250px"></asp:TextBox>
  13.             [B]<input id="btnBuscar" type="button" value="Resultado" onclick="Ajax.obtener_operarios(TextNombreBuscar.value,obtener_operarios_CallBack)" />[/B]<br>
  14.         </div>
  15.         <div id="txtResultado" Width="100px" />
  16.         </div>
  17.     </form>
  18.  
  19.     <script type="text/javascript">
  20.         function obtener_operarios_CallBack(response) {
  21.             alert("entra");
  22.             if (response.error != null) {
  23.                 alert("Se presentó un error ");
  24.                 return;
  25.             }
  26.             target = "txtResultado";
  27.             document.getElementById(target).innerHTML = response.value;
  28.         }
  29.    </script>

y el siguiente código en el .aspx.vb:
Código vb.net:
Ver original
  1. Public Class Ajax
  2.     Inherits System.Web.UI.Page
  3.  
  4.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5.         'Register Ajax.NET methods from this class
  6.         AjaxPro.Utility.RegisterTypeForAjax(GetType(Ajax))
  7.     End Sub
  8.  
  9.     <AjaxPro.AjaxMethod()> _
  10.     Public Function obtener_operarios(ByVal nombre As String) As String
  11.  
  12.         Dim conn As New MySqlConnection
  13.         Dim nombreBuscar As String
  14.         [B]nombreBuscar = UCase(Request.QueryString("nombre"))[/B]
  15.         conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("conexionMySQL").ConnectionString
  16.         Dim mysql_comando As New MySqlCommand("select distinct noperario, operario from cdp_operaciones where operario like '%" & nombreBuscar & "%'order by operario asc", conn)
  17.         Dim reader As MySqlDataReader
  18.         Dim da As New MySqlDataAdapter(mysql_comando)
  19.         Dim objRow As New TableRow()
  20.         Dim numoperario, nombreoperario As String
  21.  
  22.         Try
  23.             Using conn
  24.                 'se abre la conexion
  25.                 conn.Open()
  26.  
  27.                 With mysql_comando
  28.                     reader = .ExecuteReader()
  29.                     Dim j As Integer = 1
  30.                     While reader.Read()
  31.  
  32.                         numoperario = reader.GetValue(0)
  33.                         nombreoperario = reader.GetValue(1)
  34.  
  35.                     End While
  36.                     .Dispose()
  37.                 End With
  38.             End Using
  39.             Return (numoperario + nombreoperario)
  40.         Catch ex As Exception
  41.             MsgBox("Error en BD" & Chr(13) & Chr(13) & ex.Message)
  42.             Return "0"
  43.         Finally
  44.             conn.Close()
  45.             conn.Dispose()
  46.         End Try
  47.         Me.TextNombreBuscar.Text = ""
  48.     End Function
  49. 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
  1. <input id="btnBuscar" type="button" value="Resultado" onclick="Ajax.obtener_operarios(TextNombreBuscar.value,obtener_operarios_CallBack)" />
Código vb.net:
Ver original
  1. Dim nombreBuscar As String
  2. nombreBuscar = UCase(Request.QueryString("nombre"))

Pero no me coge el valor del TextNombreBuscar.

Alguilen me puede echar una mano?

__________________
Gracias por todo;

Un saludo