Jump to content

Aceder a Elementos de uma Página em ASP.Net atraves de C#


nunolevezinho

Recommended Posts

Boas, tenho um formulário com alguns campos de texto para o utilizador preencher. Mas estou com uma dúvida.

Tenho um ficheiro CodeBehind em c# mas não consigo aceder aos campos de texto desse formulário lá.

Tenho o meu cabeçalho assim: Página - Default.aspx

<%@ Page Title="Home" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Informito._Default" %>

E o Respectivo Formulário:

<div>
								<table class="style1">
									<tr>
										<td>Utilizador:</td>
										<td>
											<asp:TextBox ID="Utilizador" runat="server"></asp:TextBox>
										</td>
									</tr>
									<tr>
										<td>Password:</td>
										<td>
											<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
										</td>
									</tr>
									<tr>
										<td>Repetir Password:</td>
										<td>
											<asp:TextBox ID="RePassword" runat="server" TextMode="Password"></asp:TextBox>
										</td>
									</tr>
									<tr>
										<td>Nível de Acesso</td>
										<td>
										<asp:DropDownList ID="NivelAcesso" runat="server" AppendDataBoundItems="true">
										<asp:ListItem Value="-1">Escolher</asp:ListItem>
										<asp:ListItem Value="1">Funcionário</asp:ListItem>
										<asp:ListItem Value="3">Administrador</asp:ListItem>
										</asp:DropDownList>
										</td>
									</tr>
								</table>
							</div>
							 <asp:Button ID="Button1" runat="server" Text="Registar" onclick="Registar"/>

Na parte de fazer o registo: Página - Default.aspx.cs

protected void Registar(object sender, EventArgs e)
	{

	}

Na parte do Registar(), é onde não consigo aceder aos elementos. Ex: Utilizador.Text não reconhece o Utilizador.

Como o faço? Preciso de namespace especial?

Tenho estes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.SqlClient;
using Informito.Admins;

Desde já agradeço.

Link to comment
Share on other sites

  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.