lab 00_2

Post on 15-Jan-2016

223 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

asp

TRANSCRIPT

Construcción de Sitios Web Dinámicos con VISUAL STUDIO 2005 y SQL Server 2005 Enterprice Global Solution

Ing. Samuel Mestanza A.

Lab 00_2: CONTROLES DE SERVIDOR WEB DE ASP.NET

OBJETIVOS

• Familiarizarse con los principales controles de servidor Web que dispone asp.net. • Crear componentes de servidor mediante asistente de VS y directamente codificado

mostrando sus diferencias. • Manejo y creación de eventos de los componentes de servidor.

Ejercicio 1.

1. Crear una nuevo sitio Web desde VS 2005 ir a Archivo>Nuevo>Sitio Web. 2. Seleccionamos Sitio Web ASP.NET 3. En la casilla de lenguaje Escogemos el lenguaje de nuestra preferencia en este caso

C#. 4. Clic en Aceptar. 5. Por defecto la ventana del documento se nos muestra en la vista de Código. 6. Escribimos las siguientes líneas.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!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>Página sin título</title> </head> <body> <%--------------------------------------------------------------%> <script runat=server type="text/C#"> protected void btnEnviar_Click(object sender, EventArgs e) { if (txtUser.Text == " " && txtPass.Text == " ") { lblMessage.Text = "Debes Ingresar tu Usuario y Password"; txtUser.Focus(); } else { lblSaludo.Visible = true; lblUser.Visible = true; lblUser.Text = txtUser.Text; lblMessage.Text = " "; txtUser.Text = " "; txtPass.Text = " "; } } protected void btnCancelar_Click(object sender, EventArgs e) { lblMessage.Text = " "; txtUser.Text = " ";

Construcción de Sitios Web Dinámicos con VISUAL STUDIO 2005 y SQL Server 2005 Enterprice Global Solution

Ing. Samuel Mestanza A.

txtPass.Text = " "; lblSaludo.Visible = false; lblUser.Visible = false; } </script> <form id="form1" runat="server"> <%-------------------------------------------------------------%> <div> <%----------------------------------------------------------%> <asp:Label ID="lblMessage" runat="server"></asp:Label><br /> <table> <tr> <td><asp:Label ID="Label1" runat="server" Text="Usuario" /></td> <td><asp:TextBox ID="txtUser" runat="server" /></td> </tr> <td><asp:Label ID="Label2" runat="server" Text="Password" /></td> <td><asp:TextBox ID="txtPass" runat="server" TextMode="Password" /></td> <tr> <td colspan="2"> <asp:Button ID="btnEnviar" runat="server" Text="Enviar" OnClick="btnEnviar_Click" /> <asp:Button ID="btnCancelar" runat="server" Text="Cancelar" OnClick="btnCancelar_Click" /> </td> </tr> </table> <br /> <asp:Label ID="lblSaludo" runat="server" Text="Bienvenido" Visible="False" /> <asp:Label ID="lblUser" runat="server" /> <%----------------------------------------------------------%> </div> </form> </body> </html> Ejercicio 2.

1. Agregar nuevo elemento y elegir Web Forms. 2. Hacer click en el área de diseño. 3. Arrastrar los siguientes controles como se muestra en la figura.

En el área de propiedades colocar los siguientes datos: [Textbox1] ID = txtItems [Button1] ID = btnAgregar Text = Agregar Item [RequiredFieldValidator1] ControlToValidate = txtItems

Construcción de Sitios Web Dinámicos con VISUAL STUDIO 2005 y SQL Server 2005 Enterprice Global Solution

Ing. Samuel Mestanza A.

ErrorMessage= Debes coloar un Item a Ingresar [Listbox1] ID = lbItems SelectionMode = Multiple Height = 151px Width = 153px [Button2] ID = btnEnviar Text = Enviar [Label1] ID = lblMensaje Text =

4. Hacer doble click sobre el botón btnAgregar y escribir el siguiente código

protected void btnAgregar_Click(object sender, EventArgs e) { lbItems.Items.Add(txtItems.Text.ToString()); }

5. Hacer doble click sobre el botón btnEnviar y escribir el siguiente código

protected void btnEnviar_Click(object sender, EventArgs e) { lblMensaje.Text = "Tu has selecionado de la lista: <br>"; foreach (ListItem li in lbItems.Items) { if (li.Selected == true) { lblMensaje.Text += li.Text + "<br>"; } } }

Construcción de Sitios Web Dinámicos con VISUAL STUDIO 2005 y SQL Server 2005 Enterprice Global Solution

Ing. Samuel Mestanza A.

6. Ejecutar F5 y probar el ejerccio.

top related