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

Asked

Viewed 32 times

0

When using Aspnet Webform, ID components are changed dynamically, but this component cannot 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">

Result on the server:

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

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

To maintain the standard I would have to take the "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>

1 answer

0

The most practical way when you can’t use Clientidmode="Static" and take 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
  • You keep doing wrong because you changed the name of the component will have to keep changing everywhere ...

  • @Virgilionovic, the name does not change, it will always come like this, on my machine and in the approval the name and always the same, already the ID changes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.