Hi ,

I am new to asp.net .. I am trying to solve the invalid cast exception but facing some issues with that:

static private void RegisterJavaScriptFooter(string scriptName, StringBuilder scriptBlock)
    {

    ((PgDisplayBase)System.Web.HttpContext.Current.Handler).RegisterClientScriptFooterBlock(scriptName, scriptBlock.Insert(0, SetupJavaScriptHeader()).Append(SetupJavaScriptFooter()).ToString());
        }

I am getting the exception on this line :

Unable to cast object of type 'System.Web.DefaultHttpHandler' to type 'Intel.SWFactory.Platform.Common.PgDisplayBase'.

I tried resolving this as:

static private void RegisterJavaScriptFooter(string scriptName, StringBuilder scriptBlock)
    {

        try
        {
            ((PgDisplayBase)System.Web.HttpContext.Current.Handler).RegisterClientScriptFooterBlock(scriptName, scriptBlock.Insert(0, SetupJavaScriptHeader()).Append(SetupJavaScriptFooter()).ToString());
        }
        catch (InvalidCastException e)
        {
            throw(e);
    }
        }

but nothing works out ..

What it is telling you is that there is no method to cast the DefaultHttpHandler into PgDisplayBase. You'll either have to develop your own or find if the PgDisplayBase class has a method you can call to convert it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.