5
I have a relatively simple problem, but I cannot find a quick solution: I have a dropdownlist
which determines which div will be displayed, and the moment the page is loaded for the first time, it works perfectly. Soon after saving the data (ie give refresh on the page), the option that was hidden before that refresh is no longer displayed when selected in dropdownlist
.
The function below is called when selecting the dropdownlist
. Just below, the dropdownlist
where I call the function.
NOTE: I tried using jQuery, I tried calling the event on Postback page (and outside of it too), but the impression is that my div gets lost at some point.
I’ve also tried putting the display:none/block
right in the div, without success. Both Divs are fixed in the .aspx
, and are not made dynamically.
OBS. 2: Inside the divParcelaVariavel
, there are two UpdatePanel
, used on two buttons.
function MudarEstado() {
var fixas = document.getElementById('ContentPlaceHolder2_divParcelaFixas');
var variaveis = document.getElementById('ContentPlaceHolder2_divParcelaVariavel');
if (document.getElementById('ContentPlaceHolder2_dropTipoParcelas').value == 'V') {
variaveis.style.display = 'block'
fixas.style.display = 'none'
}
else {
variaveis.style.display = 'none'
fixas.style.display = 'block'
}
}
I don’t quite understand your question, but use the browser console to check the style of the
div
.– Oeslei
Basically it is the following: I have two Ivs, "Fixed Parcel" and "Variable Parcel". If, for example, I select the Variable first and save, after this postback the Fixed div is not rendered on the screen when selected in my drop. In the source code of the page it appears, but on the screen, no. And I saw by debug that this element (Document.getElementById('Contentplaceholder2_divparcelafixas') returns null.
– Aretha Freitas
Your Mudarestado function is inside a $(Document). ready(Function(){ }); ? When you inspect the page you find this div??
– Joao Paulo
No it is not, but I find the div yes. It is there but it is not displayed.
– Aretha Freitas
The funny thing is this null return, even if it is loaded internally...
– Aretha Freitas
Put on the console Document.getElementById('Contentplaceholder2_divparcelafixas') to see if it returns null. By the way the name is Contentplaceholder2_divparcelafixas or Contentplaceholder2_divparcelafixa?
– Joao Paulo
Returned null. The name is Contentplaceholder2_divparcelafixas. Typing Document.getElementById('Contentplaceholder2_divparcelavariable') it brought <div id="Contentplaceholder2_divparcelavariable" class="caixa2" style="display: None;">.
– Aretha Freitas
<div id="Contentplaceholder2_divparcelafixas" class="caixa2"> <fieldset> <Legend><b>Fixed parcel</b></Legend> <table> <tr> <td class="style9">Number of Parcels</td> <td> <input name="ctl00$Contentplaceholder2$textNumeroParcelas" type="text" id="Contentplaceholder2_textnumero parcelas" onKeyPress="javascript:fieldNumerico(this);" style="width:50px;" /> </td> "Display source code", proving that it is there.
– Aretha Freitas
It returns null, but inspecting you find... How strange.. I thought I might have misspelled the id...
– Joao Paulo
It may be that you are trying to locate the div before it exists. Or there is even some typo as you imagined @Joaopaulo.
– bfavaretto
@bfavaretto I imagined that she tried to locate before it existed, but she said that it is not dynamic and even running the code on the console with the div already there returned null.
– Joao Paulo
What I thought happened is this: The moment the page loads, I for example choose the div Variables and hidden the Fixed. When saved and return to the screen, he understands that the Fixed div still needs to be hidden and shows only the variables. Is there any way I can "zero" that state of the Divs?
– Aretha Freitas