No consigo recoger el valor del botón. Tengo lo siguiente en un .aspx:
Código aspx:
Ver original
<%@ Page Title="Página principal" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="AJAXejemplo01._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <script> var conexion1; function obtener_operario(str) { if(str=='') { return; } conexion1=crearXMLHttpRequest(); conexion1.open("GET", "Default.aspx?nombre=" + str, true); conexion1.send(null); } //*************************************** //Funciones comunes a todos los problemas //*************************************** function crearXMLHttpRequest() { var xmlHttp = null; if (window.ActiveXObject) xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest(); return xmlHttp; } </script> <div id="busqueda"> <asp:Table ID="TableBuscar" runat="server" BorderColor="Gray" CellPadding="2" CellSpacing="5" Width="300px" align="center"> <asp:TableRow Font-Bold="True" Font-Overline="False"> <asp:TableCell ID="TableCellBuscar1" HorizontalAlign="Left" Enabled="True" Width="300px"> <asp:Label ID="LabelBuscar1" runat="server" Text="Introduzca el nombre del operario:" aling="center"></asp:Label><br /> </asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell ID="TableCellBuscar2" HorizontalAlign="Left" Enabled="True" Width="250px"> <asp:TextBox ID="TextNombreBuscar" runat="server" aling="Left" Width="250px"></asp:TextBox> <asp:Label ID="LabelAsterisco1" runat="server" aling="center"></asp:Label><br /> </asp:TableCell> <asp:TableCell ID="TableCellBuscar3" HorizontalAlign="Left" Enabled="True" Width="50px"> [B]<asp:Button ID="btnBuscar" runat="server" Text="BUSCAR" OnClientClick="obtener_operario(TextNombreBuscar.value);" />[/B] </asp:TableCell> </asp:TableRow> </asp:Table> </div> <div id="tabla2"> <asp:Table ID="Table2" runat="server" BorderColor="Black" CellPadding="2" CellSpacing="5" Width="770px" align="center" HorizontalAlign="Center"> <asp:TableRow Font-Bold="True" Font-Overline="False" BackColor="Silver"> <asp:TableCell ID="Table2Cell1" HorizontalAlign="Center" Enabled="True" Width="150px" VerticalAlign="Middle"> <asp:Label ID="LabelCell1" runat="server" Text="NºOPERARIO" Font-Bold="True" Font-Underline="True" ForeColor="Black" Font-Size="Medium"></asp:Label> </asp:TableCell> <asp:TableCell ID="Table2Cell2" HorizontalAlign="Center" Enabled="True" Width="300px" VerticalAlign="Middle"> <asp:Label ID="LabelCell2" runat="server" Text="OPERARIO" Font-Bold="True" Font-Underline="True" ForeColor="Black" Font-Size="Medium"></asp:Label> </asp:TableCell> <asp:TableCell ID="Table2Cell3" HorizontalAlign="Center" Enabled="True" Width="170px" VerticalAlign="Middle"> <asp:Label ID="LabelCell3" runat="server" Text="DETALLE MENSUAL" Font-Bold="True" Font-Underline="True" ForeColor="Black" Font-Size="Medium"></asp:Label> </asp:TableCell> <asp:TableCell ID="Table2Cell4" HorizontalAlign="Center" Enabled="True" Width="150px" VerticalAlign="Middle"> <asp:Label ID="LabelCell4" runat="server" Text="MES" Font-Bold="True" Font-Underline="True" ForeColor="Black" Font-Size="Medium"></asp:Label> </asp:TableCell> </asp:TableRow> </asp:Table> </div> </asp:Content>
Lo que quiero es que cuando se clique en el Boton "btnBuscar", que lo he puesto en negrita, con la variable que se escribe en "TextNombreBuscar" vaya a la función "obtener_operario" y este, como indica la función, mande a "Default.aspx?nombre=" + str" la variable que se introduce y haga lo que se le indica en el page_load de la pagina Default.asp.
Este es el codigo que tengo en la pagina Default.aspx que esta programada en vb.net:
Código vb.net:
Ver original
Imports MySql.Data.MySqlClient Imports System.Configuration Imports Oracle.ManagedDataAccess.Client Imports Oracle.ManagedDataAccess.Types Imports System.IO Public Class _Default 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(_Default)) Dim nombreBuscar As String Dim conn As New MySqlConnection 'se apunta a la cadena de conexion guardada en el archivo Web.config 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, objRow1 As New TableRow() Dim numoperario, nombre As String 'If IsPostBack = False Then Try Using conn 'se abre la conexion conn.Open() With mysql_comando reader = .ExecuteReader() Dim i As Integer = 1 While reader.Read() objRow = New TableRow() Dim objCell1, objCell2, objCell3, objCell4 As New TableCell() Dim linkDetalle, linkMes As String 'crear los hyperlinks para tener acceso a los detalles mensuales Dim sw1 As StringWriter = New StringWriter Dim ht1 As HtmlTextWriter = New HtmlTextWriter(sw1) Dim sw2 As StringWriter = New StringWriter Dim ht2 As HtmlTextWriter = New HtmlTextWriter(sw2) numoperario = reader.GetValue(0) nombre = reader.GetValue(1) If numoperario <> "" Then objCell1.Controls.Add(New LiteralControl(numoperario)) objCell1.HorizontalAlign = HorizontalAlign.Center objCell2.Controls.Add(New LiteralControl(nombre)) objCell2.HorizontalAlign = HorizontalAlign.Left ' Create the a. ht1.AddAttribute(HtmlTextWriterAttribute.Href, "HorasOperarios.aspx?numOperario=" & numoperario) ht1.RenderBeginTag(HtmlTextWriterTag.A) ht1.Write("ver") ' End all the tags. ht1.RenderEndTag() linkDetalle = sw1.ToString() objCell3.Controls.Add(New LiteralControl(linkDetalle)) objCell3.HorizontalAlign = HorizontalAlign.Center ' Create the a. ht2.AddAttribute(HtmlTextWriterAttribute.Href, "HorasOperariosMes.aspx?numOperario=" & numoperario) ht2.RenderBeginTag(HtmlTextWriterTag.A) ht2.Write("ver") ' End all the tags. ht2.RenderEndTag() linkMes = sw2.ToString() objCell4.Controls.Add(New LiteralControl(linkMes)) objCell4.HorizontalAlign = HorizontalAlign.Center If i Mod 2 = 0 Then objCell1.BackColor = Drawing.Color.AliceBlue objCell2.BackColor = Drawing.Color.AliceBlue objCell3.BackColor = Drawing.Color.AliceBlue objCell4.BackColor = Drawing.Color.AliceBlue End If objRow.Cells.Add(objCell1) objRow.Cells.Add(objCell2) objRow.Cells.Add(objCell3) objRow.Cells.Add(objCell4) Table2.Rows.Add(objRow) i = i + 1 End If End While .Dispose() End With End Using Catch ex As Exception 'mensaje("Error en BD" & Chr(13) & Chr(13) & ex.Message) Finally conn.Dispose() End Try 'End If End Sub End Class
Alguien me puede echar una mano? Aunque sea al cuello....
