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>
a7mad.3ezz
  • 101
  • 1
  • 6
  • Have you tried moving the $(".lDel_23").click(); to occur before $(this).dialog('close'); ? – ORION Oct 23 '12 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 ! – a7mad.3ezz Oct 23 '12 at 13:29
  • You mean, that server click handler doesn't triggered? Show your markup – Yuriy Rozhovetskiy Oct 23 '12 at 13:34
  • this is the html code after its generated, forget about server markup my issue is a 'client side' – a7mad.3ezz Oct 23 '12 at 13:39
  • Do you render this script in each ItemTemplate? – Yuriy Rozhovetskiy Oct 23 '12 at 13:52
  • yes Yuriy, it changes the script with the id of each row so that everything is in correct shape for the HTML to run flawlessly, the solution is as (thanks to) Tallmaris said exactly, all i had to do is use the native Javascript click trigger instead of the jQuery click function and it worked pretty good ! – a7mad.3ezz Oct 23 '12 at 14:53
  • @a7mad.3ezz, in my opinion, it's not very well solution to render script for dialog with each item. – Yuriy Rozhovetskiy Oct 23 '12 at 15:18
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/18480/discussion-between-yuriy-rozhovetskiy-and-a7mad-3ezz) – Yuriy Rozhovetskiy Oct 23 '12 at 15:24

1 Answers1

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();

Community
  • 1
  • 1
Tallmaris
  • 7,605
  • 3
  • 28
  • 58
  • thank you very much, it worked fine .. I find it odd to have to do it this way though ! – a7mad.3ezz Oct 23 '12 at 13:42
  • 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 :) – Tallmaris Oct 23 '12 at 13:47