Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6757795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:41:55+00:00 2026-05-26T13:41:55+00:00

I am just learning how to use classes in my projects. I have been

  • 0

I am just learning how to use classes in my projects. I have been working on a DataAccessClass.cs and am doing well (I think).
Taking a break from data access, I decided to try to make a void into a class. This void sends a message to the client as a javascript alert. It works well, but has to be included on each page. When I tried to make it a class, I was informed that my class does not contain a definition for ClientScript. I included all the “using” directives from the original page to no avail… Any hints or suggestions would be greatly appreciated.

The original code:

//------------------------------------------------------------------------------
//Name: SendErrorMessageToClient
//Abstract: show alert on client side
//------------------------------------------------------------------------------

protected void SendErrorMessageToClient(string strErrorType, string strErrorMessage)
{
    string strMessageToClient = "";

    //Allow single quotes on client-side in JavaScript
    strErrorMessage = strErrorMessage.Replace("'", "\\'");

    strMessageToClient = "<script type=\"text/javascript\" language=\"javascript\">alert( '" + strErrorType + "\\n\\n" + strErrorMessage + "' );</script>";

    this.ClientScript.RegisterStartupScript(this.GetType(), "ErrorMessage", strMessageToClient);

}

Messages are sent into this void like this:

if (DataAccessClass.OpenSqlConnection(ref Conn, strConn, out strErrorMessage) == false)
        {
            string strErrorType = "Database Connection Error:";
            SendErrorMessageToClient(strErrorType, strErrorMessage);
        }

Or this:

catch (Exception excError)
    {
        string strErrorType = "Unhandled Exception:";
        string strErrorMessage = excError.Message;
        SendErrorMessageToClient(strErrorType, strErrorMessage);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:41:56+00:00Added an answer on May 26, 2026 at 1:41 pm

    You are receiving the error as ‘Clientscript’ is a property derived from a System.Web.UI.Page and by moving into a separate class file, you no longer have access to this property.

    You could solve this by passing in the page as well, and amending the code to

    protected void SendErrorMessageToClient(string strErrorType, string strErrorMessage, Page page)
    {
        string strMessageToClient = "";
    
        //Allow single quotes on client-side in JavaScript
        strErrorMessage = strErrorMessage.Replace("'", "\\'");
    
        strMessageToClient = "<script type=\"text/javascript\" language=\"javascript\">alert( '" + strErrorType + "\\n\\n" + strErrorMessage + "' );</script>";
    
        page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorMessage", strMessageToClient);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning Objective-C as my first language and understand Classes, Objects, instances,
I just started learning Ruby coming from Java. In Java you would use packages
I'm just learning Java... I have 2 custom classes. One is a Fraction and
I'm on break from classes right now and decided to spend my time learning
I've been learning Objective-C and just recently started using classes (instead of having everything
I am just learning how to use Terracotta after discovering it about a month
I'm just learning Perl. When is it advisable to use OO Perl instead of
I am just learning about app.config in respect of creating custom sections. I have
I'm just learning to work with partial classes in VB.NET and VS2008. Specifically, I'm
I'm 14 and have been learning java for about 4/5 months. I'm coding a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.