Inquiridor
Formulario de cadastro em um Dialog

Pergunta
-
Galera, Tenho uma pagina em aspx que contem apenas um botão de cadastrar, ao clicar nesse botão abre um dialog em Jquery com um formulário de cadastro, até ai tudo bem, mas quando preencho os campos e clico no botão cadastrar, esses mesmos TextBox estão indo vazios para o CodeBehind, e ainda não sei o que fazer. Alguém pode ajudar ?
Codigo aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Dialog._Default" %> <%@ Import Namespace="System.Collections.Generic" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Teste Dialog</title> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script> <script language="JavaScript"> var botaoFoiClicado = false; ///============================================================================ /// <summary> Responsavel por chamar o Dialog </summary> /// <remarks> Autor: Luis Gustavo /// Versão: *.* </remarks> ///============================================================================ $(function () { $('#btnCadastrar').click(function (event) { if (!botaoFoiClicado) { event.preventDefault(); $('#DialogConfirmacao').dialog('open'); } }); $('#DialogConfirmacao').dialog({ autoOpen: false, width: 350, height: 300, buttons: { "Cadastrar": function () { botaoFoiClicado = true; $('#btnCadastrar').click(); }, "Cancelar": function () { botaoFoiClicado = false; $(this).dialog("close"); } } }); }); </script> </head> <body> <form id="form1" runat="server"> <asp:Button id="btnCadastrar" runat="server" Text="Cadastrar" onclick="btnCadastrar_Click" /> <div id="DialogConfirmacao" title="Cadastrar"> <asp:Label ID="lblNome" runat="server" Text="Nome"></asp:Label><br/> <asp:TextBox ID="txtNome" runat="server">teste</asp:TextBox> <br /> <asp:Label ID="lblEmail" runat="server" Text="Email"></asp:Label> <br /> <asp:TextBox ID="txtEmail" runat="server">teste</asp:TextBox> <br /> <br /> <asp:Label ID="lblResult" runat="server" Text=""></asp:Label> </div> </form> </body> </html>
Code-Behind:
#region USINGS using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Dados; #endregion namespace Dialog { public partial class _Default : System.Web.UI.Page { ///============================================================================ /// <summary> Referente ao Carregamento da pagina </summary> /// <remarks> Autor: Luis Gustavo /// Versão: *.* </remarks> ///============================================================================ protected void Page_Load(object sender, EventArgs e) { } ///============================================================================ /// <summary>Evento responsavel pelo click do botão Cadastrar </summary> /// <remarks> Autor: Luis Gustavo /// Versão: *.* </remarks> ///============================================================================ protected void btnCadastrar_Click(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(txtEmail.Text) && !string.IsNullOrEmpty(txtNome.Text)) { //lblResult.Text = string.Empty; LigacaoBD ligaDados = new LigacaoBD(); Usuarios user = new Usuarios(); user.Nome = txtNome.Text; user.Email = txtEmail.Text; ligaDados.MontarInsercao(user.Nome, user.Email); } else lblResult.Text = "Preencha os Campos Corretamente."; } catch (Exception ex) { throw ex; } } } }
Minha aplicação rodando:
O Que ocorre quando clico Em cadastrar com os campos preenchidos conforme mostrado acima:
http://luisgustavo12.wordpress.com/
Todas as Respostas
-
O problema é que você está usando um mesmo botão para chamar o popup e para Salvar, você precisa criar outro botão e colocar o evento btnCadastrar_Click nele.
Elvis Rodrigues Analista Desenvolvedor .Net MCTS .Net Framework, SQL Server 2005, WPF, ASP NET foxelv@hotmail.com -
-
-
#region USINGS using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Dados; #endregion namespace Dialog { public partial class _Default : System.Web.UI.Page { ///============================================================================ /// <summary> Referente ao Carregamento da pagina </summary> /// <remarks> Autor: Luis Gustavo /// Versão: *.* </remarks> ///============================================================================ protected void Page_Load(object sender, EventArgs e) { } ///============================================================================ /// <summary>Evento responsavel pelo click do botão Cadastrar </summary> /// <remarks> Autor: Luis Gustavo /// Versão: *.* </remarks> ///============================================================================ protected void btnCadastrar_Click(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(txtEmail.Text) && !string.IsNullOrEmpty(txtNome.Text)) { //lblResult.Text = string.Empty; LigacaoBD ligaDados = new LigacaoBD(); Usuarios user = new Usuarios(); user.Nome = txtNome.Text; user.Email = txtEmail.Text; ligaDados.MontarInsercao(user.Nome, user.Email); } } catch (Exception ex) { throw ex; } } protected void btnSalvar_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtEmail.Text) && !string.IsNullOrEmpty(txtNome.Text)) { //lblResult.Text = string.Empty; LigacaoBD ligaDados = new LigacaoBD(); Usuarios user = new Usuarios(); user.Nome = txtNome.Text; user.Email = txtEmail.Text; ligaDados.MontarInsercao(user.Nome, user.Email); } } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Dialog._Default" %> <%@ Import Namespace="System.Collections.Generic" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Teste Dialog</title> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script> <script language="JavaScript"> var botaoFoiClicado = false; ///============================================================================ /// <summary> Responsavel por chamar o Dialog </summary> /// <remarks> Autor: Luis Gustavo /// Versão: *.* </remarks> ///============================================================================ $(function () { $('#btnCadastrar').click(function (event) { if (!botaoFoiClicado) { event.preventDefault(); $('#DialogConfirmacao').dialog('open'); } }); $('#DialogConfirmacao').dialog({ autoOpen: false, width: 350, height: 300, buttons: { "Cadastrar": function () { botaoFoiClicado = true; $('#btnSalvar').click(); }, "Cancelar": function () { botaoFoiClicado = false; $(this).dialog("close"); } } }); }); </script> </head> <body> <form id="form1" runat="server"> <asp:Button id="btnCadastrar" runat="server" Text="Cadastrar" onclick="btnCadastrar_Click" /> <asp:Button ID="btnSalvar" runat="server" Text="Salvar" onclick="btnSalvar_Click" /> <div id="DialogConfirmacao" title="Cadastrar"> <asp:Label ID="lblNome" runat="server" Text="Nome"></asp:Label><br/> <asp:TextBox ID="txtNome" runat="server"></asp:TextBox> <br /> <asp:Label ID="lblEmail" runat="server" Text="Email"></asp:Label> <br /> <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox> <br /> <br /> </div> </form> </body> </html>
Ai está o código.
http://luisgustavo12.wordpress.com/
-
-