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
RadhaKrishnaKiJayaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
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.
0
Julian HansenCommented:
The position of the script will not affect this as your dialog binding is done in the document load - so it will bind and it should work, however Chinmay's suggestion of relocating it is a good one as it is good practice to locate your script in common areas where it can be easily located.

As to why this is not working - we would need to see a link to see the problem. If you can setup a test link that replicates the issue we can have a look.

Also, please check your console (F12) for errors - report those here.

To the problem - I would be wary of using the debugger statement unless you are a seasoned JavaScript developer. There is the risk of leaving it active which could cause problems. If you know what you are doing with debugging put a break point on the code and debug from there. You could also put a console.log('#btnArchive clicked') and then view the results in the archive.

Some questions
Are you creating any content dynamically on the page?
Is your button rendered with the page or added afterwards?
When you say it does not work - do you mean you click it - does not work - click it again it works
OR
You click it - does not work - you have to reload the page and then it works?

Can you try changing your click handler to use the .on()

jQuery('body').on('click','#btnArchive', function () {
  jQuery("#confirmDialogMessage").dialog("open");
});

Open in new window


Does that work?

EDIT: Corrected code to put .on() in the right place
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RadhaKrishnaKiJayaAuthor Commented:
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.
0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Chinmay PatelChief Technical NinjaCommented:
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.
0
RadhaKrishnaKiJayaAuthor Commented:
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.
0
Julian HansenCommented:
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.
0
Chinmay PatelChief Technical NinjaCommented:
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.
0
RadhaKrishnaKiJayaAuthor Commented:
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.
0
Julian HansenCommented:
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.
0
RadhaKrishnaKiJayaAuthor Commented:
I can understand what you are saying. But I have limitations what I can post . Also it has thousands of LOC. Thanks anyway
0
RadhaKrishnaKiJayaAuthor Commented:
Your F12 suggestion helped me to find the problem. Thanks.
0
Julian HansenCommented:
Ok, glad you came right.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.