Page Context

daveamour
daveamour used Ask the Experts™
on
I am writing a method in a class which will send an error message to a client browser as plain text or as Javascript if their browser supports Javascript.  I know there are easier ways of doing this but its more of an academic question really.

The code in my class has no page context or access to the Request object etc.  I guess I need to pass this from my code in my page to the class, I cant quite get this right though.

Code in web page:

UserMessage.Text = DTS.Classes.Miscellaneous.SendClientErrorMessage (<SomeObjectGoesHere>, "wibble");

Code in Class:

          public static string SendClientErrorMessage (<SomeObjectGoesHere>, string ErrorMessage)
          {
               HttpBrowserCapabilities objBrowser = new HttpBrowserCapabilities();

               objBrowser = objRequest.Browser;

               if (objBrowser.JavaScript)
               {
                    return "<script language=\"JavaScript\">alert ('" + ErrorMessage + "');</script>";
               }
               else
               {
                    return "There was an error as follows: " + ErrorMessage;
               }
          }

Any ideas please?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
In the best case,  you could just pass a bool into your function.  As that hides a web detail from your class.  If you feel the class is sufficiently bound to the web that you want to pass in the object, I would define the function like this:

public static string SendClientErrorMessage (System.Web.HttpRequest request, string ErrorMessage)
{
   if(request.Browser.JavaScript)
}

then you call it from your web page like this:
  (SendClientErrorMessage(Context.Request, "ErrMsgHere");



Author

Commented:
Cheers dude, knew it was something like that, just not familliar enough with the classes yet.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial