Problem with Jquery dialog

Asked

Viewed 80 times

2

I have a ListView which creates some buttons dynamically according to Idpassoworkflow, and as the step I need presents a message to the user confirms whether or not to execute the action, only that the dialog Jquery does not open when clicked on button.

ListView what I use to press the 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>
  • instead of using . click, try using . on("click" .. objects created dynamically after the instance of . click has no event Rigger, already using the on("click" the current objects and the new ones will receive the Rigger. I have not reached the fore, but it does not cost to try.

  • I took the test, but it still won’t open

2 answers

2


You are making the bind of an event on ready of jquery after the page is already ready, so this event will never run, so remove the $(function () { ... }) of the method CheckConfirm.

Another point, I really don’t know what you intend to do with $(this).click += new EventArgs(this.lnkGravar_Click);, This seems to me a valid syntax to do the Bind of an event Server-Side in the C#, but not for the bind of an event Client-Side in the JavaScript, then try commenting the same 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')
      });
    //});
  }
}
  • Toby, the idea of += new Eventargs was to call my method on the Server-Side even though the user click yes... despite the effort the message did not appear on the screen .

  • To call a method in Server-Side from Java, use the method __doPostBack('<% this.lnkGravar.ClientID %>', '')

1

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

$(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 it this way

Browser other questions tagged

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