ki_ko Posted May 26, 2008 at 06:29 PM Report Share #187645 Posted May 26, 2008 at 06:29 PM Tenho gridview onde listo tudo o que tenho numa tabela, depois dou a possibilidade de alterar e editar, e quando edito coloquei uma textbox e um customvalidator que vai a tabela ver se existe um campo ja com o mesmo nome e se existir dispara o customValidator. mas nao tou a conseguir por isto a funcionar, nem sequer quando carrego no update ele entra na funcao do custamValidator, alguem me pode ajudar? deixo em baixo o meu codigo: funcao protected void CustomValidator1_ServerValidate1(object source, ServerValidateEventArgs args) { LabelTESTE.Text = args.Value.ToString(); conexao = new SqlConnection(); conexao.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TravelGuide;Data Source=.\\SQLEXPRESS;"; conexao.Open(); try { SqlCommand comando = new SqlCommand("Select Cod_aeroporto from T_Aeroporto where Cod_aeroporto='"+args.Value.ToString()+"' ", conexao); if ((String.Compare(comando.ExecuteScalar().ToString(), null)) != 0) { args.IsValid=false; LabelTESTE.Text = "JA EXISTENTE"; } } catch (Exception ex) { args.IsValid=true; LabelTESTE.Text = "OK"; } } editar na gridview <EditItemTemplate> <asp:TextBox ID="TextBoxEditCodArp" runat="server" MaxLength="3"></asp:TextBox><br /> <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBoxEditCodArp" ErrorMessage="expressao invalida, deve conter 3 caracteres(A-Z) maiusculos." ValidationExpression='^[A-Z]{3,3}$'></asp:RegularExpressionValidator><br /> <asp:CustomValidator ID="CustomValidatorCodArpEditar" runat="server" ControlToValidate="TextBoxEditCodArp" ErrorMessage="Erro ja existe arp com esse codigo" OnServerValidate="CustomValidator1_ServerValidate1"></asp:CustomValidator> </EditItemTemplate> Link to comment Share on other sites More sharing options...
DanielAmorim Posted May 26, 2008 at 06:54 PM Report Share #187653 Posted May 26, 2008 at 06:54 PM A validação no servidor só ocorre quando fazes o pedido ao servidor. Ao carregares no botão de update esta a ser feito algum pedido? Daniel Amorim VP for xRTML http://www.xrtml.org http://www.realtime.co Link to comment Share on other sites More sharing options...
ki_ko Posted May 26, 2008 at 06:56 PM Author Report Share #187654 Posted May 26, 2008 at 06:56 PM penso que quando carrego no update da gridview ele faz um pedido, pelo menos akilo deveria fazer um postback logo existe pedido.penso eu. Link to comment Share on other sites More sharing options...
DanielAmorim Posted May 26, 2008 at 07:07 PM Report Share #187658 Posted May 26, 2008 at 07:07 PM se puderes mete ai o código todo da tua página. Daniel Amorim VP for xRTML http://www.xrtml.org http://www.realtime.co 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