nunolevezinho Posted August 22, 2012 at 10:49 AM Report Share #473128 Posted August 22, 2012 at 10:49 AM 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 More sharing options...
cro Posted August 22, 2012 at 02:13 PM Report Share #473146 Posted August 22, 2012 at 02:13 PM Verifica os namespaces... assumo que tens isso dentro de um form runat=server no site.master... Link to comment Share on other sites More sharing options...
nunolevezinho Posted August 22, 2012 at 02:49 PM Author Report Share #473153 Posted August 22, 2012 at 02:49 PM Sim tenho e os namespaces estão bem :\ Deve estar a faltar-me qualquer coisa. Assumindo que tenho os namespaces bem não deveria ser algo do género: string Username = Utilizador.Text; ? Link to comment Share on other sites More sharing options...
poliveira1978 Posted March 11, 2013 at 12:19 PM Report Share #498720 Posted March 11, 2013 at 12:19 PM tenta string Username=(TextBox)Page.FindControl("Utilizador").Text; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now