locked
error CS0103: The name 'ClientScript' does not exist in the current context RRS feed

  • Question

  • User-523892225 posted

    I am upgrading the framework of a very old application from 3.5 to 4.71. I have a calendar icon that when clicked is supposed to open a week view Outlook calendar. It works fine in 3.5 but in 4.7.1 it fails with an "Unable to get property 'GoToDate' of undefined or null reference" on the following javascript function:

    function gotoDate(date) {
        //alert(date);
        document.calendar.GoToDate(date);
    }

    So I go to the code behind to where I believe the problem lies:

    public partial class MainOutlookCalendar : System.Web.UI.UserControl
    {        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DateTime date;
    
                if (Request.QueryString["Date"] != null)
                {
                    date = Convert.ToDateTime(Request.QueryString["Date"].ToString(), System.Globalization.CultureInfo.CurrentCulture);
                }
                else
                {
                    date = DateTime.Now;
                }
    
                date.ToString();
                    
                Type cstype = this.GetType();
                if (Page.ClientScript.IsClientScriptBlockRegistered(cstype, "OutlookInit") == false)
                {
                    Page.ClientScript.RegisterStartupScript(cstype, "OutlookInit", "<script language='javascript'> gotoDate('" + date.ToString("M/d/yyyy", System.Globalization.CultureInfo.CurrentCulture) + "'); </script>");
                }
    
            }
    ....
        }

    cstype = {Name = "calendar_usercontrols_mainoutlookcalendar_ascx" FullName = "ASP.calendar_usercontrols_mainoutlookcalendar_ascx"}

    Page = {ASP.calendar_genericcalendar_aspx}

    However, ClientScript = error CS0103: The name 'ClientScript' does not exist in the current context

    Both IsClientScriptBlockRegistered and RegisterStartupScript say the same, which makes sense due to the ClientScript error.

    My question is, what is causing ClientScript not to exist in the current content? I've google it and cannot find an answer, or at least one I am able to transfer to my problem. I did find some code on the Microsoft ClientScriptManager Property that closely resembles this code: 

    https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.clientscriptmanager?view=netframework-4.7.2 

    Wednesday, December 12, 2018 2:30 PM

Answers

  • User-523892225 posted

    So it appears that the app is unable to access my Outlook while in Visual Studio, even when running via Ctrl-F5. That is why is fails. It works fine if I just run it from my local machine without involving VS.

    Learn something new everyday.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 12, 2018 4:12 PM

All replies

  • User-523892225 posted

    So it appears that the app is unable to access my Outlook while in Visual Studio, even when running via Ctrl-F5. That is why is fails. It works fine if I just run it from my local machine without involving VS.

    Learn something new everyday.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 12, 2018 4:12 PM
  • User753101303 posted

    Hi,

    Not sure what happens but how can you test this page if the UserControl doesn't even compile ? You are using a web site project rather than a web application project ?

    Wednesday, December 12, 2018 4:21 PM