Problem with Jquery dialog

2

I have a ListView that creates some buttons dynamically according to IdPassoWorkflow, and according to the step I need presents a message to the user confirms whether or not to execute the action, except that the Jquery dialog window does not open when the button is clicked.

% of what I use to load buttons

<asp:ListView ID="lvBotoes" runat="server">
    <ItemTemplate>
      <asp:LinkButton ID="lnkGravar" OnClick="lnkGravar_Click" runat="server" CssClass="btnInline"
        OnClientClick='<%#Eval("IdPassoWorkflow","javascript:return CheckConfirm({0});" )%>'
        CommandArgument='<%# Eval("IdPassoWorkflow") %>'>                
        <%# TextoBotao(Container.DataItem) %></asp:LinkButton>
    </ItemTemplate>
</asp:ListView>

My Jquery

<link type="text/css" href="../CSS/Jquery/jquery-ui-1.8.18.custom.css" rel="stylesheet" />
<link href="../CSS/Jquery/estilos.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../Scripts/modernizr.js"></script>
<script type="text/javascript" src="../Scripts/jquery-min.js"></script>
<script type="text/javascript" src="../Scripts/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript">
  var SqlType = '<% =vsSqlType.Value%>';
  var PassoWorkflow = parseInt(<% =vsIdPassoWorkflow.Value %>);

   function  CheckConfirm(IdPassoWorkflow) { 
    if (IdPassoWorkflow == 2)
    {
        $(function() { 
          var opcoesDialogo = {
              autoOpen: false,  
              buttons: {
                  'Não': function(event) { $(this).dialog("close"); }, 
                  'Sim': function(event) {$(this).click += new EventArgs(this.lnkGravar_Click);  }
              }
          };
          $('.EncaminharGestor').dialog(opcoesDialogo); 

          $('#lnkGravar').click(function() {
              $('.EncaminharGestor').dialog('open')
          });
      });
    }
  }
</script>

Message to be displayed.

<div class="EncaminharGestor" title="Janela de Confirmação">
  <p>Encaminhar para o Gestor?</p>
</div>

The generated Html

<td colspan="2" class="Button">

              <a href="javascript:__doPostBack('ctl00$BodyContent$lvBotoes$ctrl0$lnkGravar','')" class="btnInline" id="BodyContent_lvBotoes_lnkGravar_0" onclick="javascript:return CheckConfirm(1);">Salvar</a>

              <a href="javascript:__doPostBack('ctl00$BodyContent$lvBotoes$ctrl1$lnkGravar','')" class="btnInline" id="BodyContent_lvBotoes_lnkGravar_1" onclick="javascript:return CheckConfirm(2);">Encaminhar</a>

              <a href="javascript:__doPostBack('ctl00$BodyContent$lvBotoes$ctrl2$lnkGravar','')" class="btnInline" id="BodyContent_lvBotoes_lnkGravar_2" onclick="javascript:return CheckConfirm(5);">Excluir</a>

        </td>
    
asked by anonymous 01.12.2015 / 18:56

2 answers

2

You are binding an event in ready of jquery after the page is already ready, so this event will never be executed, then remove $(function () { ... }) from CheckConfirm method.

Another point, I really do not know what you want to do with $(this).click += new EventArgs(this.lnkGravar_Click); , this seems like a valid syntax for doing the Bind of an event Server-Side on C# , but not for bind of an event Client-Side no JavaScript , so try commenting on it to see if the code works.

var SqlType = '<% =vsSqlType.Value%>';
var PassoWorkflow = parseInt(<% =vsIdPassoWorkflow.Value %>);

function  CheckConfirm(IdPassoWorkflow) { 
  if (IdPassoWorkflow == 2)
  {
    //$(function() { Este bind do $(document).ready é desnecesario.
      var opcoesDialogo = {
        autoOpen: false,  
        buttons: {
          'Não': function(event) { $(this).dialog("close"); }, 
          'Sim': function(event) {
            //$(this).click += new EventArgs(this.lnkGravar_Click); Esta sintaxe não me parece valida.
          }
        }
      };
      $('.EncaminharGestor').dialog(opcoesDialogo); 

      $('#lnkGravar').click(function() {
        $('.EncaminharGestor').dialog('open')
      });
    //});
  }
}
    
01.12.2015 / 20:23
1

Friend, within its function has an eventlistener, tries to put it in the document ready.

$(document).ready(function(){
  $('input[type="button"]').click(function(){
    CheckConfirm(2);
  });

});

function CheckConfirm(IdPassoWorkflow) { 
    if (IdPassoWorkflow == 2)
    {
        $(function() { 
          var opcoesDialogo = {
              autoOpen: false,  
              buttons: {
                  'Não': function(event) { $(this).dialog("close"); }, 
                  'Sim': function(event) {$(this).click += new EventArgs(this.lnkGravar_Click);  }
              }
          };
          $('.EncaminharGestor').dialog(opcoesDialogo); 

          $('.EncaminharGestor').dialog('open');
      });
    }
}

Try this out

    
01.12.2015 / 19:55