Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Modal dialog does not open on click of a button

Hi Experts,

I have a button on my form. When I click it, it supposed to popup a modal form. My problem is it pops up the modal form sometime but not all the time. I am using asp.net and c#. Any reason why it is happening. I have attached the code. When "#btnArchive" is clicked, it should popup the window all the time.

Thanks in advance.
Temp.txt
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Your code looks fine but I have one suggestion. Can you move the <script> block to the header of the page? or maybe in the footer of the page?

If that does not work then put a debugger; statement in your script block at the beginning and inside

jQuery("#btnArchive").click(function () {
debugger;
            	jQuery("#confirmDialogMessage").dialog("open");
               
            });

Open in new window


so that we can figure out whether it is being called or not.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Thanks a lot for all the replay. I tried the .on(), but it did not work.  It is not creating content dynamically. For one shipping id when I click the button it pops up the window. But another shipping id when I click the 'Archive' button it does not pop up the window. In fact it does not go inside the 'click' event.

Thanks.
Please share the ASPX if you can. It will help us figure out what needs to be done. Also as Julian suggested did you try and check the console for any errors?

And if you are using Visual Studio - you can try to debug it will show you step by step how things are going, if you do not want to use the Visual Studio from Dev Toolbar itself you can debug the code but that might be bit difficult if you are new to script debugging.
Actually I have already share some ASPX code. For some ID it does not execute the click function at all. I am not sure what is blocking. Can you please tell me how to check console error? Because I pressed F12 but it did not show any error.

Thanks.
For one shipping id when I click the button it pops up the window. But another shipping id when I click the 'Archive' button it does not pop up the window. In fact it does not go inside the 'click' event
jQuery('body').on('click','#btnArchive', function () {

Open in new window

Your click handler is bound to an id, id's must be unique but in your comment you are saying "but another shipping id, when I click the button" - indicating you have more than one button - which means your click handler should not be bound to an id - it should be bound to a class or a selector that allows for more than one.
That code is not code. It is a snippet of code. I am thinking if there is anything else that can interfere with your code that is why I am asking for the entire ASPX.

Coming to the second question, when you run the code in browser, press F12 a window will appear. In that window there is a tab called Console. click on that and check if there are any messages/errors in that.
Thanks for your help.  Actually "pnlArchiveAddressConfirmDialog"  was getting invisible depending on some condition. That is why click event was not working. But I really appriciate your thoughts and help.
Actually "pnlArchiveAddressConfirmDialog"  was getting invisible depending on some condition. That is why click event was not working
This is way it is important to post as much code as is relevant - otherwise we can only guess at the problem.
I can understand what you are saying. But I have limitations what I can post . Also it has thousands of LOC. Thanks anyway
Your F12 suggestion helped me to find the problem. Thanks.
Ok, glad you came right.