How to validate the return of a value using Jquery on a component that does not support ClientIDMode="Static" in Asp.net?

0

When using ASPNet WebForm, ID of components are dynamically changed, but this component can not use ClientIDMode="Static" to keep the same ID.

example :

<asp:HiddenField runat="server" ID="MenuSelecionado" value="processo" />
<asp:HiddenField runat="server" ID="AbaSelecionado" value="aba1"  />

Result on local machine:

 <input type="hidden" name="ctl00$ContentPlaceHolder1$MenuSelecionado"
      id="ctl00_ContentPlaceHolder1_MenuSelecionado" value="processo">

<input type="hidden" name="ctl00$ContentPlaceHolder1$AbaSelecionado"
      id="ctl00_ContentPlaceHolder1_AbaSelecionado" value="aba1">

Server result:

<input type="hidden" name="ctl00$ContentPlaceHolder1$MenuSelecionado" 
      id="ContentPlaceHolder1_MenuSelecionado" value="processo">

<input type="hidden" name="ctl00$ContentPlaceHolder1$AbaSelecionado" 
      id="ContentPlaceHolder1_AbaSelecionado" value="aba1">

In order to keep the default I would have to get " name " in place of ID or validate the value received and switch between local and remote machine , example:

<script type="text/javascript">
    $(document).ready(function(){
      //recebe o id do content 
      var menuatual = document  
        .querySelector('#ctl00_ContentPlaceHolder1_MenuSelecionado').value;
      //recebe o id da aba 
      var abaatual  = document
        .querySelector('#ctl00_ContentPlaceHolder1_AbaSelecionado').value;

      if (menuatual == "") { 
           // alert("não foi enviado nenhum menu no input");
      } else {
           //  alert("O menu que veio selecionado foi :" + menuatual);
           // alert("A Aba Selecionada foi :" + abaatual);

            // REMOVE AS CLASS ACTIVES DO TITULO
        $('.tab-content').find('.tab-pane').removeClass('active');

             // REMOVE AS CLASS ACTIVES DO CONTENT
       $('.nav.nav-tabs').find('li').removeClass('active')

        // alert("Removeu todas as active titulo");
        // alert("Removeu todas as active do content");
        //adiciona o active que retornou
        $('#'+abaatual).addClass('active'); 
        $('#'+menuatual).addClass('active in');

       }      
    });
 </script>
    
asked by anonymous 30.07.2018 / 16:02

1 answer

0

The most practical way when you can not use ClientIDMode="Static" and get it by name. would look like this:

var menuatual = document.querySelector('input[name="ctl00$ContentPlaceHolder1$MenuSelecionado"]').value
var abaatual  = document.querySelector('input[name="ctl00$ContentPlaceHolder1$AbaSelecionado"]').value
    
30.07.2018 / 16:46