0

Here is some Html + jQuery ui dialog code genereated by asp.net for the browser ..

to my eyes it looks fine but the issue is, confirm button triggers click event for the link with the class specified, although the event does not get triggered.

[Update: I changed the "$(".lDel_23").click();" to document.location.href= "javascript:__doPostBack('ctl00$ContentPlaceHolder1$ListView_Sections$ctrl1$LinkButton_Delete','')" and it called the function .. so the problem seems to be the click trigger not able to work correctly with the href of the link set to a javascript method .. although trying the manual click works the jQuery click trigger calling doesnt .. does that make any sense ???? ]

    <a href="#" id="aDel_23"></a>
    <a id="ctl00_ContentPlaceHolder1_ListView_Sections_ctrl1_LinkButton_Delete" title="Delete" class="lDel_23" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ListView_Sections$ctrl1$LinkButton_Delete','')"></a>
     <div id="dialog_23" title="Confirm Delete">
           Delete Section [section name]
     </div>

     <script type="text/javascript">
            $(document).ready(function() {
                $("#dialog_23").dialog({
                    autoOpen: false,
                    modal: true,
                    width: 400
                });
                // Link to open the dialog
                $("#aDel_23").click(function(event) {
                    event.preventDefault();
                    $("#dialog_23").dialog({
                        buttons: {
                            'Confirm': function() {
                                $(this).dialog('close');
                                $(".lDel_23").click();
                            },
                            'Cancel': function() {
                                $(this).dialog('close');
                            }
                        }
                    });

                    $('#dialog_23').dialog("open");
                });
            });
    </script>
8
  • Have you tried moving the $(".lDel_23").click(); to occur before $(this).dialog('close'); ? Commented Oct 23, 2012 at 13:27
  • tried and its the same, tried another javascript code instead that redirects to another page to make sure the code runs correctly, it worked ! only problem is that click even doesn't get triggered after the call ! Commented Oct 23, 2012 at 13:29
  • You mean, that server click handler doesn't triggered? Show your markup Commented Oct 23, 2012 at 13:34
  • this is the html code after its generated, forget about server markup my issue is a 'client side' Commented Oct 23, 2012 at 13:39
  • Do you render this script in each ItemTemplate? Commented Oct 23, 2012 at 13:52

1 Answer 1

2

Apparently it is a bit more fiddly to trigger a link on an "a" tag. See if this questions helps out: trigger a click on a anchor link

Basically change this: $(".lDel_23").click(); to $(".lDel_23").get(0).click();

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much, it worked fine .. I find it odd to have to do it this way though !
Yes it's strange. The difference is that the left click() is jQuery code, while the working one is normal Javascript (element native click trigger I mean). The linked SO question and answers will give you all the info you need :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.