Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Filipe Lourenco

não encontra id

Recommended Posts

function toggleVisibility(){
	  
	   if (document.getElementById(Panel_calendario))
	   {
	   alert("ola");
	  if (document.getElementById(Panel_calendario).style.visibility=="hidden"){
		alert("ola1");
		 document.getElementById(Panel_calendario).style.visibility=="visible";
		 }
	  else {
		 document.getElementById(Panel_calendario).style.visibility=="hidden";
		 alert("ola2");
		 }
		 }
	  }
no ficheiro aspx html tenho

<input type="button" id="Button1" value="..." class="text" onclick="toggleVisibility();" />

 

não reconhece o document.getElementById

Compartilhar este post


Link para o post
Compartilhar em outros sites

Filipe, ao invés de document.getElementById(Panel_calendario) tente algo como document.getElementById('<$=Panel_calendario.ClientID$>'), caso Panel_calendario seja um ServerControl, ou document.getElementById('Panel_calendario') caso Panel_calendario seja o ID de um HtmlControl

Compartilhar este post


Link para o post
Compartilhar em outros sites

o elemento é este

<asp:Panel ID="Panel_calendario" runat="server" Height="203px" Width="202px" Visible="False">
                               <br />
               <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Width="163px"></asp:Calendar>
                           </asp:Panel>

mas mesmo com ('<$=Panel_calendario.ClientID$>') não faz o alert

Compartilhar este post


Link para o post
Compartilhar em outros sites

Filipe, teria como voce postar a versão final do código que você escreveu?

Compartilhar este post


Link para o post
Compartilhar em outros sites

aqui vai

 

<script type="text/javascript">
 function toggleVisibility(){
	 
	  
	  if (document.getElementById("<%=painel.ClientID %>").style.visibility="hidden"){
		alert("ola1");
		 document.getElementById("<%=painel.ClientID %>").style.visibility="visible";
		 }
	  else {
		 document.getElementById("<%=painel.ClientID %>").style.visibility="hidden";
		 alert("ola2");
		 }
		 
	  }
</script>


<input type="button" id="Button1"  value="..." class="text" onclick="toggleVisibility();" />
							<asp:Panel ID="painel" runat="server" Height="203px" Width="202px" Visible="False">
								<br />
				<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Width="163px"></asp:Calendar>
							</asp:Panel>

atenção que tudo está dentro de um <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

Compartilhar este post


Link para o post
Compartilhar em outros sites

protected void Page_Load(object sender, EventArgs e)
	{
	   
	   
		registaMostraCal();

			ImageButton1.Attributes.Add("onClick","return mostra('"+painel.ClientID+"');");
	   
   }
	private void registaMostraCal(){
		String jscript = "<script language='JavaScript'>";
		
		
		jscript += "function mostra(id){";
		jscript += "var painel=document.getElementById(id);";
	   
		jscript += "if (painel.style.display=='none'){ painel.style.display=''};";

	 
		jscript += "}</script>";


		Page.ClientScript.RegisterClientScriptBlock(GetType(), "Default", jscript);

		   
	}

 

<asp:Panel ID="painel" runat="server" Height="203px" Width="202px" Style="display:none">
								<br />
				<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Width="163px"></asp:Calendar>
							</asp:Panel>

Então é assim eu tirei o atributo Visible e pus o style com o display a none.Através do código que está em cima eu consigo pô-lo visible mas ao que parece faz um refresh à página e automaticamente põe como none pq?

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.