Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/03/2011, 15:33
artur_
 
Fecha de Ingreso: junio-2010
Mensajes: 9
Antigüedad: 13 años, 11 meses
Puntos: 0
Pregunta Web Form en C#

Hola a toda la comunidad, estoy empezando a hacer mis primeras aplicaciones en ASP.NET usando Visual Studio 2010, resulta que hice un proyecto ASP.NET con lenguaje C# y estoy haciendo mis primeras practicas
1.- Hice una nuevo proyecto con una pagina Default.aspx y en ella una pequeña tabla con dos campos TextBox, uno para el nombre y otro para el apellido, no estoy seguro si tiene que llevar un form para enviar los datos. algo como "<form action="archivo.aspx.cs" metod="post">"

Código:
<h2>GUARDAR DATOS EN SQL CON ASPX</h2>
    <table style="width: 100%;">
        <tr>
            <td>Nombre:</td>
            <td><input id="Text1" type="text" /></td>            
        </tr>
        <tr>
            <td>Apellidos:</td>
            <td><input id="Text2" type="text" /></td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td>
                &nbsp;
                <asp:Button ID="Button1" runat="server" Text="Guardar" onclick="Conexion" />
            </td>
        </tr>
    </table>
2.- En el botón Button1 le asigne un evento que se llama Conexion que está en el archivo Default.aspx.cs

Código:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace ACADES
{
    public partial class _Default : System.Web.UI.Page
    {
        

        protected void Conexion(object sender, EventArgs e)
        {
            SqlCommand cm = new SqlCommand();
            SqlConnection cn = new SqlConnection("Data Source=INTELIGENCIAART\\SQLEXPRESS;Initial Catalog=ACADES;Integrated Security=True;");
            cm.Connection = cn;
            cm.CommandType = CommandType.Text;
            cm.CommandText = "INSERT INTO Alumnos(persona,nombre) values(@nombre,@persona)";
            SqlParameter par_nombre = cm.Parameters.Add("@nombre", SqlDbType.NChar);
            SqlParameter par_apellido = cm.Parameters.Add("@persona", SqlDbType.NChar);
            par_nombre.Value = "Text1.Text";
            par_apellido.Value = "Text2.Text";
            cn.Open();
            cm.ExecuteNonQuery();
            cn.Close();
        }

      
    }
}
En este archivo se encuentra mi conexión a mi base de datos, la pregunta en si es ¿Cómo paso el valor de los textbox cituados en el primer archivo Default.aspx al archivo Default.aspx.cs? exactamente

estas dos lineas son las que no me funcionan:


par_nombre.Value = "Text1.Text";
par_apellido.Value = "Text2.Text";