I have a 50 TextBox of that type:
<asp:TextBox ID="txt_DetImovel0" runat="server" AutoPostBack="true" OnTextChanged="txt_DetImovel0_TextChanged"></asp:TextBox>
<asp:TextBox ID="txt_DetImovel1" runat="server" AutoPostBack="true" OnTextChanged="txt_DetImovel0_TextChanged"></asp:TextBox>
<asp:TextBox ID="txt_DetImovel2" runat="server" AutoPostBack="true" OnTextChanged="txt_DetImovel0_TextChanged"></asp:TextBox>
I have a function in javascript that changes the value of the TextBox when it selects a color (Color Picker)
The problem is that in debug mode I realize that this "txt_DetImovel0_TextChanged" function is being called one for each field! even though .js is only changing 1 field. (I put an alert ('test'), and it only really appears once, but when I debug I see that it is called several times.
Questions:
Is there any way to know or monitor who is firing this function? since in debug mode I only see the actions of the code behind.
How to make only the field that has the value modified by .js actually call this function.?
OBS: I discovered that when I have autopostback = true it will actually send to every field, even though I only changed the value of 1 field !!! Is this a .NET BUG?
The image below shows what cadas textbox does, it is the color picker, every time it changes the color it gets the value.
Complementcodetomakeiteasiertounderstand.ThereisastepthatheassemblessomeJStobetriggeredassoonasyouchangethevalueoftheTextBox:
txt.Append(@"<script type=text/javascript>");
txt.Append("Corescolhe(" + txt_DetImovel0.ClientID + ");");
txt.Append("Corescolhe(" + txt_DetImovel1.ClientID + ");");
txt.Append("Corescolhe(" + txt_DetImovel2.ClientID + ");");
txt.Append("Corescolhe(" + txt_DetImovel3.ClientID + ");");
txt.Append("Corescolhe(" + txt_DetImovel4.ClientID + ");");
txt.Append("Corescolhe(" + txt_DetImovel5.ClientID + ");");
txt.Append("Corescolhe(" + txt_DetImovel6.ClientID + ");");
txt.Append("Corescolhe(" + txt_DetImovel7.ClientID + ");");
txt.Append("Corescolhe(" + txt_DetImovel8.ClientID + ");");
txt.Append("Corescolhe(" + txt_DetImovel9.ClientID + ");");
txt.Append("</script>");
and JS
function Corescolhe(elemento) {
$(elemento).spectrum({
showPaletteOnly: false,
className: "full-spectrum",
showInitial: true,
chooseText: "OK",
cancelText: "cancelar",
showPalette: true,
preferredFormat: "hex",
localStorageKey: "spectrum.demo",
move: function (color) {
updateBorders(color);
},
hide: function (color) {
updateBorders(color);
// alert('irá mudar');
$(elemento).val(color);
}
};
But the problem is that JS really only changes TextBox X but all Textboxes fire the autopostBack at the same time, if I debug it, I see that the txt_DetImovel0_TextChanged function is called once for each component and not for what just changed the value!