Usuário com melhor resposta
Apresentar informação apos selecionar opção do Radio Button List

Pergunta
-
Prezados,
Gostaria de criar uma página de pesquisa de satisfação, nesta página terei apenas uma pergunta com com 4 opções exibidas em um radio button.
<asp:RadioButtonList ID="RbPesquisaSatisfacao" runat="server">
<asp:ListItem>Muito Satisfeito</asp:ListItem>
<asp:ListItem>Satisfeito</asp:ListItem>
<asp:ListItem>Insatisfeito</asp:ListItem>
<asp:ListItem>Muito Insatisfeito</asp:ListItem>
</asp:RadioButtonList><asp:TextBox ID="TxPesquisaSatisfacao" runat="server" Rows="5" TextMode="MultiLine"></asp:TextBox>
Gostaria de exibir um TextBox caso as opções Insatisfeito ou Muito Insatisfeito seja acionado, a intenção e que este TextBox seja apresentado sem o AutoPostBack da pagina, talvez usando ajax.
Alguem teria uma boa solução? Obrigado!
Renatin- Editado Renato.s.almeida quinta-feira, 22 de dezembro de 2011 22:04
Respostas
-
Veja se ajuda:
Código ASPX:
<asp:RadioButtonList ID="RbPesquisaSatisfacao" runat="server" AutoPostBack="True" onselectedindexchanged="RbPesquisaSatisfacao_SelectedIndexChanged"> <asp:ListItem>Muito Satisfeito</asp:ListItem> <asp:ListItem>Satisfeito</asp:ListItem> <asp:ListItem>Insatisfeito</asp:ListItem> <asp:ListItem>Muito Insatisfeito</asp:ListItem> </asp:RadioButtonList> <asp:TextBox ID="TxPesquisaSatisfacao" Visible="False" runat="server" Rows="5" TextMode="MultiLine"></asp:TextBox>
Código C#:
protected void RbPesquisaSatisfacao_SelectedIndexChanged(object sender, EventArgs e) { if (this.RbPesquisaSatisfacao.SelectedIndex == 2 || this.RbPesquisaSatisfacao.SelectedIndex == 3) { this.TxPesquisaSatisfacao.Visible = true; } else { this.TxPesquisaSatisfacao.Visible = false; } }
Para evitar o post vc pode utilizar o controle Ajax UpdatePanel, veja este link:http://www.asp.net/web-forms/videos/aspnet-ajax/how-do-i-use-the-conditional-updatemode-of-the-updatepanel
[]s!
Fernando Henrique Inocêncio Borba Ferreira
while(alive){ this.WriteCode(); }
Blog: http://ferhenriquef.wordpress.com/
Twitter: @ferhenrique
- Editado Fernando Henrique Inocêncio Borba FerreiraMicrosoft employee, Moderator sexta-feira, 23 de dezembro de 2011 10:47
- Marcado como Resposta Renato.s.almeida sexta-feira, 23 de dezembro de 2011 23:06
Todas as Respostas
-
Veja se ajuda:
Código ASPX:
<asp:RadioButtonList ID="RbPesquisaSatisfacao" runat="server" AutoPostBack="True" onselectedindexchanged="RbPesquisaSatisfacao_SelectedIndexChanged"> <asp:ListItem>Muito Satisfeito</asp:ListItem> <asp:ListItem>Satisfeito</asp:ListItem> <asp:ListItem>Insatisfeito</asp:ListItem> <asp:ListItem>Muito Insatisfeito</asp:ListItem> </asp:RadioButtonList> <asp:TextBox ID="TxPesquisaSatisfacao" Visible="False" runat="server" Rows="5" TextMode="MultiLine"></asp:TextBox>
Código C#:
protected void RbPesquisaSatisfacao_SelectedIndexChanged(object sender, EventArgs e) { if (this.RbPesquisaSatisfacao.SelectedIndex == 2 || this.RbPesquisaSatisfacao.SelectedIndex == 3) { this.TxPesquisaSatisfacao.Visible = true; } else { this.TxPesquisaSatisfacao.Visible = false; } }
Para evitar o post vc pode utilizar o controle Ajax UpdatePanel, veja este link:http://www.asp.net/web-forms/videos/aspnet-ajax/how-do-i-use-the-conditional-updatemode-of-the-updatepanel
[]s!
Fernando Henrique Inocêncio Borba Ferreira
while(alive){ this.WriteCode(); }
Blog: http://ferhenriquef.wordpress.com/
Twitter: @ferhenrique
- Editado Fernando Henrique Inocêncio Borba FerreiraMicrosoft employee, Moderator sexta-feira, 23 de dezembro de 2011 10:47
- Marcado como Resposta Renato.s.almeida sexta-feira, 23 de dezembro de 2011 23:06
-
Bom dia amigo, para saber o item que foi selecionado no seu RadioButtonList faz assim:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="javascriptRadioButtonList.aspx.cs" Inherits="JQTest.javascriptRadioButtonList" %> <!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></title> <script language="javascript" type="text/javascript"> function GetRadioButtonValue(id) { var radio = document.getElementsByName(id); for (var j = 0; j < radio.length; j++) { if (radio[j].checked) alert(radio[j].value); } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:RadioButtonList ID="rblTeste" runat="server"> <asp:ListItem Text="item1" Value="1" Selected="False"></asp:ListItem> <asp:ListItem Text="item2" Value="2" Selected="True"></asp:ListItem> <asp:ListItem Text="item3" Value="3" Selected="False"></asp:ListItem> </asp:RadioButtonList> </div> <input type="button" value="Submit" onclick="GetRadioButtonValue('<%= rblTeste.ClientID %>')" /> </form> </body> </html>
Rodrigo Reis Ferreira
Microsoft Certified -
Valew Rodrigo,
Fernando fiz na mesma ideia que você disse, e esta funcionando o problema e que nao consegui, adicionar o ajax, com o UpdatePanel ele não executa o evento associado a ele.
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:ScriptManager ID="ScriptManager2" runat="server"> </asp:ScriptManager> <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" onselectedindexchanged="RbPesquisaSatisfacao_SelectedIndexChanged"> <asp:ListItem Value="M_Satisfeito">Muito Satisfeito</asp:ListItem> <asp:ListItem Value="Satisfeito">Satisfeito</asp:ListItem> <asp:ListItem Value="Insatisfeito">Insatisfeito</asp:ListItem> <asp:ListItem Value="M_Insatisfeito">Muito Insatisfeito</asp:ListItem> </asp:RadioButtonList> <asp:ValidationSummary ID="ValidationSummary1" runat="server" style="color: #FF0000; font-size: small" /> </ContentTemplate> </asp:UpdatePanel> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/Pesquisa.png" onclick="IbtPesquisaSatisfacao_Click" /> <br /> <asp:TextBox ID="TextBox1" runat="server" Rows="5" TextMode="MultiLine" Visible="false" Width="302px"></asp:TextBox>
protected void RbPesquisaSatisfacao_SelectedIndexChanged(object sender, EventArgs e) { if (RbPesquisaSatisfacao.SelectedValue == "Insatisfeito" || RbPesquisaSatisfacao.SelectedValue == "M_Insatisfeito") { LbInfoInsatiscacao.Visible = true; TxPesquisaSatisfacao.Visible = true; } else { LbInfoInsatiscacao.Visible = false; TxPesquisaSatisfacao.Visible = false; LbDescricaoPesquisaSatisfacao.Text = ""; } } protected void BtPesquisaSatisfacao_Click(object sender, EventArgs e) { if (RbPesquisaSatisfacao.SelectedValue == "Insatisfeito" || RbPesquisaSatisfacao.SelectedValue == "M_Insatisfeito") { if (TxPesquisaSatisfacao.Text == "") { LbDescricaoPesquisaSatisfacao.Text = "Caso esteja Insatisfeito com o atendimento. Favor preencher o campo de descrição"; } else LbDescricaoPesquisaSatisfacao.Text = ""; this.ModalPopupExtender.Show(); } else LbDescricaoPesquisaSatisfacao.Text = ""; this.ModalPopupExtender.Show(); }
Sem utilizar o UpdatePanel a ações estão sendo executadas, mais com o postback na página.
Renatin- Editado Renato.s.almeida sexta-feira, 23 de dezembro de 2011 21:17
-
Olá Renatin,
Veja se isto lhe ajuda, senão lhe envio os arquivos com o exemplo:
Código ASPX:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:RadioButtonList ID="RbPesquisaSatisfacao" runat="server" AutoPostBack="True" onselectedindexchanged="RbPesquisaSatisfacao_SelectedIndexChanged"> <asp:ListItem>Muito Satisfeito</asp:ListItem> <asp:ListItem>Satisfeito</asp:ListItem> <asp:ListItem>Insatisfeito</asp:ListItem> <asp:ListItem>Muito Insatisfeito</asp:ListItem> </asp:RadioButtonList> <asp:TextBox ID="TxPesquisaSatisfacao" runat="server" Rows="5" TextMode="MultiLine" Visible="False"></asp:TextBox> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="RbPesquisaSatisfacao" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> </div> </form> </body> </html>
Código C#:public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void RbPesquisaSatisfacao_SelectedIndexChanged(object sender, EventArgs e) { if (this.RbPesquisaSatisfacao.SelectedIndex == 2 || this.RbPesquisaSatisfacao.SelectedIndex == 3) { this.TxPesquisaSatisfacao.Visible = true; } else { this.TxPesquisaSatisfacao.Visible = false; } } } }
Obs.: veja que o código do arquivo aspx possui mais referência ao UpdatePanel e ao ScriptManager
[]s!
Fernando Henrique Inocêncio Borba Ferreira
while(alive){ this.WriteCode(); }
Blog: http://ferhenriquef.wordpress.com/
Twitter: @ferhenrique