1

I am currently making a client to gather data from a webservice. Sometimes the connection fails and I put a try catch to prevent the page from going to error page. What I would like to do is to show a pop-up on exeption, to tell the user to try again. I know about "alert" on JS, but can't really make it pop without user action (i.e. clicking a button).

Is this the wisest approach? How can I do this?

Thank you

4
  • 1
    You can add label to your page and if exception is raised, then add some message to the label. Commented Dec 27, 2013 at 17:34
  • 2
    You can absolutely make an alert pop w/o the user clicking on something. Commented Dec 27, 2013 at 17:36
  • How do you collect data from the webservice? Commented Dec 27, 2013 at 17:36
  • If you just add the alert() to the page from server-side code, outside of a JavaScript function, then it will run when the page loads. Commented Dec 27, 2013 at 17:36

1 Answer 1

3

If you really need a popup, you don't have to have a user click a button to get it:

var alertWindow= window.open("", "", "width=200,height=200");
   alertWindow.document.write("I know about: YOUR THING HERE");

However, popups are annoying and I would really suggest that you have a <div> in your main page with an id="exceptionDiv" and then doing something like this:

page.html

<div id="exceptionDiv"></div>

page.js

var exceptionDiv = document.getElementById("exceptionDiv");
exceptionDiv.innerHTML = "I know about: YOUR THING HERE";
Sign up to request clarification or add additional context in comments.

3 Comments

This is exactly what I would do. No annoying popup. Just have a div display the error.
Thank you for the answer. I was about to try this approach (which seems to suit me), but I am using .cs code behind, so how can I "getElementById" of an element when I am not using script? Sorry If I'm not very clear, but I'm not that enlightened on this subject. Thank you once again.
Just a heads up. I tried the ViewBag approach and it worked fine. Thank you all.

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.