1

I'm using jQuery .Ajax to call a method from my codebehind which must be a public static method. Because of this, I can't access any of my pages controls unless they are declared also as public static and I don't want any of my variables or anything declared that way. If I return a List in a WebMethod, what can I do in the catch to have an error bubble back up to the client side page? The only way I can see being able to do this the way I want is if the WebMethod returns a string instead of a List.

0

1 Answer 1

2

Why not just throw an exception? Here is a good article on how to catch and parse WebMethod exceptions using jQuery.

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

2 Comments

Thing is I was trying to wrap my code in my WebMethod in a try catch and wasn't able to return ex.Message in the catch because it was a string and the WebMethod returns a List<T>. I guess I don't need to do a try/catch at all after reading that article. Thanks for the link :)
Don't try to shoe-horn everything into one response type. Throwing exceptions across a boundry is a perfectly acceptable way of communicating an error. :)

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.