Link to home
Create AccountLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

The name 'ScriptManager' does not exist in the current context csc

C:\Windows\Microsoft.NET\Framework\v2.0.50727>csc /t:library /out:mm_datepicker.
dll /r:System.dll,System.Drawing.dll,System.Web.dll, c:\inetpub\wwwroot\OmegaLov
e_CS\OL_Web\mm_datepicker.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.1434
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

c:\inetpub\wwwroot\OmegaLove_CS\OL_Web\mm_datepicker.cs(543,13): error CS0103:
        The name 'ScriptManager' does not exist in the current context

I have at the bottom of the file see attached snippet.
do a search on ScriptManager.
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
 
namespace mm_date
{
    /// <summary>
    /// DatePicker - Generates drop down select objects for date selection
    /// Client side javascript ensures only valid date returned.
    /// </summary>
 
    [DefaultProperty("Text"),
        ToolboxData("<{0}:datepicker runat=server></{0}:datepicker>")]
 
    public class datepicker : System.Web.UI.WebControls.WebControl, System.Web.UI.IPostBackDataHandler
    {
        //Declarations
        private int begyear = 1980;
        private int endyear = System.DateTime.Today.Year;
        private int date_mode = 1;
        private int form_level = 0;
        private DateTime initial_date = System.DateTime.Today;
        private int sel_month = System.DateTime.Today.Month;
        private int sel_day = System.DateTime.Today.Day;
        private int sel_year = System.DateTime.Today.Year;
        private int picked_month = 0;
        private int picked_day = 0;
        private int picked_year = 0;
        private string selected_date;
        private string sel_date_convert;
        private DateTime date_picked;
        private string control = "Datepicker";
 
        //Define Properties
 
        //Control Release & About
        [Bindable(false),
        Category("About"),
        DefaultValue(""),
        Description("Control:  Datepicker\n" +
            "Version:  Ver 1.01 - 12/01/2003\n" +
            "Author:   Michael McLain\n" +
            "Desc:      Date dropdown selection control\n")]
 
        public string Control
        {
            get
            {
                return control;
            }
            set
            {
                control = value;
            }
        }
 
 
        //Posted Date Returned
        [Bindable(true),
        Category("Returned Values"),
        DefaultValue(""),
        Description("Returned date selected (string)")]
        public string Selected_Date
        {
            get
            {
                return selected_date;
            }
            set
            {
                selected_date = value;
            }
        }
 
        public bool LoadPostData(String postDataKey, NameValueCollection values)
        {
            selected_date = values[this.UniqueID.ToString()];
            sel_date_convert = values[this.UniqueID.ToString() + "_conv"];
            date_picked = System.DateTime.Parse(sel_date_convert).Date;
            Month = date_picked.Month;
            Day = date_picked.Day;
            Year = date_picked.Year;
            if (this.EnableViewState)
            {
                this.initial_date = date_picked;
            }
            return false;
        }
 
        public void RaisePostDataChangedEvent()
        {
        }
 
        //Returned date in datetime format
        [Bindable(true),
        Category("Returned Values"),
        DefaultValue(""),
        Description("Returned date selected (datetime)")]
        public DateTime Date_Picked
        {
            get
            {
                return date_picked;
            }
            set
            {
                date_picked = value;
            }
        }
 
        //Returned Month
        [Bindable(false),
        Category("Returned Values"),
        DefaultValue(""),
        Description("Returned month selected (int)")]
        public int Month
        {
            get
            {
                return picked_month;
            }
            set
            {
                picked_month = value;
            }
        }
 
        //Returned Day
        [Bindable(false),
        Category("Returned Values"),
        DefaultValue(""),
        Description("Returned day selected (int)")]
        public int Day
        {
            get
            {
                return picked_day;
            }
            set
            {
                picked_day = value;
            }
        }
 
        //Returned year
        [Bindable(false),
        Category("Returned Values"),
        DefaultValue(""),
        Description("Returned year selected (int)")]
        public int Year
        {
            get
            {
                return picked_year;
            }
            set
            {
                picked_year = value;
            }
        }
 
        //Begin Year
        [Bindable(true),
        Category("Setup Values"),
        DefaultValue(""),
        Description("Beginning Year Select Range")]
        public int YearRange_Start
        {
            get
            {
                return begyear;
            }
 
            set
            {
                begyear = value;
            }
        }
 
        //End Year
        [Bindable(true),
        Category("Setup Values"),
        DefaultValue(""),
        Description("Ending Year Select Range")]
        public int YearRange_End
        {
            get
            {
                return endyear;
            }
 
            set
            {
                endyear = value;
            }
        }
 
        //Initial date selected
        [Bindable(true),
        Category("Setup Values"),
        DefaultValue(""),
        Description("Initial selected date")]
        public DateTime Initial_Date
        {
            get
            {
                return initial_date;
            }
 
            set
            {
                initial_date = value;
            }
        }
 
        //Date format returned (in string format)
        //Included for backward compatibility to Classic ASP version
        [Bindable(true),
        Category("Setup Values"),
        DefaultValue(""),
        Description("Date format returned in (Selected_Date).\n1 - MM/DD/YYYY\n2 - DD/MM/YYYY\n3 - YYYYMMDD\n4 - universal format")]
        public int Date_Mode
        {
            get
            {
                return date_mode;
            }
 
            set
            {
                date_mode = value;
            }
        }
 
        //Form level index to allow handling multiple forms per page.
        [Bindable(false),
        Category("Setup Values"),
        DefaultValue(""),
        Description("Document form index level")]
        public int Form_Level
        {
            get
            {
                return form_level;
            }
 
            set
            {
                form_level = value;
            }
        }
 
        /// <summary>
        /// Render this control to the output parameter specified.
        /// </summary>
        /// <param name="output"> The HTML writer to write out to </param>
        protected override void Render(HtmlTextWriter output)
        {
            string cid = this.UniqueID.ToString();
            string isSelected = "";
            string docref = "document.forms[" + this.form_level.ToString() + "]." + cid;
            string onchg = " onChange=\"tg_mm_setdays('" + docref + "'," + date_mode.ToString() + ")\"";
            string objinit = "<script language=javascript>tg_mm_setdays('" + docref + "'," + date_mode.ToString() + ")</script>";
 
            //Build control style
            string ostyle = "";
            string c_ostyle = "";
            string ostylevalue = "";
            int stylecount = this.Style.Count;
            foreach (string stmp in this.Style.Keys)
            {
                ostylevalue = this.Style[stmp].ToString();
                c_ostyle = c_ostyle + stmp + ": " + ostylevalue + "; ";
            }
 
            StringBuilder s = new StringBuilder();
 
            //Set component container if applied style
            //Container used to handle grid layout mode
            if (c_ostyle != "")
            {
                s.Append("<div style=\"" + c_ostyle + "\">");
            }
 
            //Build select drop down styles
            string color = "";
            if (!this.ForeColor.IsEmpty)
            {
                color = this.ForeColor.Name;
                if (color != "")
                {
                    if (!this.ForeColor.IsNamedColor && !this.ForeColor.IsSystemColor)
                    {
                        color = "#" + color.Substring(2, 6);
                    }
                }
            }
            string backcolor = "";
            if (!this.BackColor.IsEmpty)
            {
                backcolor = this.BackColor.Name;
                if (backcolor != "")
                {
                    if (!this.BackColor.IsNamedColor && !this.BackColor.IsSystemColor)
                    {
                        backcolor = "#" + backcolor.Substring(2, 6);
                    }
                }
            }
            string fontname = this.Font.Name;
            string fontsize = this.Font.Size.ToString();
            string cssclass = this.CssClass;
            bool fontstyle = this.Font.Italic;
            bool fontbold = this.Font.Bold;
            bool underline = this.Font.Underline;
            bool overline = this.Font.Overline;
            bool strikeout = this.Font.Strikeout;
            string textdecoration = "";
 
            //TEXT-DECORATION: underline overline line-through
            if (underline || overline || strikeout)
            {
                textdecoration = "TEXT-DECORATION: ";
                if (underline)
                {
                    textdecoration = textdecoration + "underline ";
                }
                if (overline)
                {
                    textdecoration = textdecoration + "overline ";
                }
                if (strikeout)
                {
                    textdecoration = textdecoration + "strikeout ";
                }
                textdecoration = textdecoration + ";";
            }
 
            if (cssclass != "")
            {
                cssclass = " class=\"" + cssclass + "\"";
            }
            ostyle = " style=\"";
            if (fontname != "")
            {
                ostyle = ostyle + "FONT-FAMILY: " + fontname + ";";
            }
            if (fontsize != "")
            {
                ostyle = ostyle + "FONT-SIZE: " + fontsize + ";";
            }
            if (fontstyle)
            {
                ostyle = ostyle + "FONT-STYLE: italic;";
            }
            if (fontbold)
            {
                ostyle = ostyle + "FONT-WEIGHT: bold;";
            }
 
            if (color != "")
            {
                ostyle = ostyle + "COLOR: " + color + ";";
            }
 
            if (backcolor != "")
            {
                ostyle = ostyle + "BACKGROUND-COLOR: " + backcolor + ";";
            }
 
            if (textdecoration != "")
            {
                ostyle = ostyle + textdecoration;
            }
            ostyle = ostyle + "\"" + cssclass;
 
            //Build Month Dropdown
            sel_month = initial_date.Month;
            sel_day = initial_date.Day;
            sel_year = initial_date.Year;
 
            //Determine days in Month
            DateTime wrkdate = initial_date.Date;
            int daysinmonth = 0;
            while (sel_month == wrkdate.Month)
            {
                daysinmonth = wrkdate.Day;
                wrkdate = wrkdate.AddDays(1);
            }
            s.Append("\n<select name=\"" + cid + "_month\"" + onchg + ostyle + ">\n");
            isSelected = checkselected(1, sel_month);
            s.Append("<option value=1" + isSelected + ">Jan</option>\n");
            isSelected = checkselected(2, sel_month);
            s.Append("<option value=2" + isSelected + ">Feb</option>\n");
            isSelected = checkselected(3, sel_month);
            s.Append("<option value=3" + isSelected + ">Mar</option>\n");
            isSelected = checkselected(4, sel_month);
            s.Append("<option value=4" + isSelected + ">Apr</option>\n");
            isSelected = checkselected(5, sel_month);
            s.Append("<option value=5" + isSelected + ">May</option>\n");
            isSelected = checkselected(6, sel_month);
            s.Append("<option value=6" + isSelected + ">Jun</option>\n");
            isSelected = checkselected(7, sel_month);
            s.Append("<option value=7" + isSelected + ">Jul</option>\n");
            isSelected = checkselected(8, sel_month);
            s.Append("<option value=8" + isSelected + ">Aug</option>\n");
            isSelected = checkselected(9, sel_month);
            s.Append("<option value=9" + isSelected + ">Sep</option>\n");
            isSelected = checkselected(10, sel_month);
            s.Append("<option value=10" + isSelected + ">Oct</option>\n");
            isSelected = checkselected(11, sel_month);
            s.Append("<option value=11" + isSelected + ">Nov</option>\n");
            isSelected = checkselected(12, sel_month);
            s.Append("<option value=12" + isSelected + ">Dec</option>\n");
            s.Append("</select>\n");
 
            //Build Day Dropdown
            s.Append("\n<select name=\"" + cid + "_day\"" + onchg + ostyle + ">\n");
            int i;
            string lc_i;
            for (i = 1; i < daysinmonth + 1; i++)
            {
                lc_i = i.ToString();
                if (lc_i.Length == 1)
                {
                    lc_i = "0" + lc_i;
                }
                isSelected = checkselected(i, sel_day);
                s.Append("<option value=" + i.ToString() + isSelected + ">" + lc_i + "</option>\n");
            }
            s.Append("</select>\n");
 
            //Build Year Dropdown
            s.Append("\n<select name=\"" + cid + "_year\"" + onchg + ostyle + ">\n");
            for (i = begyear; i <= endyear; i++)
            {
                lc_i = i.ToString();
                isSelected = checkselected(i, sel_year);
                s.Append("<option value=" + i.ToString() + isSelected + ">" + i.ToString() + "</option>\n");
            }
            s.Append("</select>\n");
 
            //Build hidden input type to hold current date
            s.Append("\n<input type=hidden name=\"" + cid + "\">\n");
            s.Append("\n<input type=hidden name=\"" + cid + "_conv\">\n");
 
            //Close container for applied styles
            if (c_ostyle != "")
            {
                s.Append("</div>");
            }
 
            //Add in object initialization for Netscape inline script bug
            s.Append(objinit);
 
            //Render control
            output.Write(s.ToString());
        }
 
        protected string checkselected(int current_selection, int compair_selection)
        {
            if (current_selection == compair_selection)
            {
                return " SELECTED";
            }
            return "";
        }
 
        //		protected void Write_Client_Scripts()
        /// <summary> 
        ///    Add date validation JavaScript to the Page 
        /// </summary> 
        /// <param name="e"></param> 
        override protected void OnPreRender(EventArgs e)
        {
            StringBuilder s = new StringBuilder();
            s.Append("\n<SCRIPT LANGUAGE=javascript>\n");
            s.Append("function tg_mm_daysinmonth(lnMonth,lnYear) {\n");
            s.Append("var dt1, cmn1, cmn2, dtt, lflag, dycnt, lmn\n");
            s.Append("lmn = lnMonth-1\n");
            s.Append("dt1 = new Date(lnYear,lmn,1)\n");
            s.Append("cmn1 = dt1.getMonth()\n");
            s.Append("dtt=dt1.getTime()+2332800000\n");
            s.Append("lflag = true\n");
            s.Append("dycnt=28\n");
            s.Append("while (lflag) {\n");
            s.Append("   dtt = dtt + 86400000\n");
            s.Append("   dt1.setTime(dtt)\n");
            s.Append("   cmn2 = dt1.getMonth()\n");
            s.Append("   if (cmn1!=cmn2) {\n");
            s.Append("      lflag = false }\n");
            s.Append("   else {dycnt = dycnt + 1}}\n");
            s.Append("if (dycnt > 31) {dycnt = 31}\n");
            s.Append("return dycnt\n");
            s.Append("}\n");
            s.Append("\n");
            s.Append("function tg_mm_setdays(sobjname, datemode){\n");
            s.Append("var dobj = eval(sobjname + \"_day\")\n");
            s.Append("var mobj = eval(sobjname + \"_month\")\n");
            s.Append("var yobj = eval(sobjname + \"_year\")\n");
            s.Append("var hobj = eval(sobjname)\n");
            s.Append("var hobjconv = eval(sobjname + \"_conv\")\n");
            s.Append("var monthdays = tg_mm_daysinmonth(mobj.options[mobj.selectedIndex].value,yobj.options[yobj.selectedIndex].value)\n");
            s.Append("var selectdays = dobj.length\n");
            s.Append("var curdy = dobj.options[dobj.selectedIndex].value\n");
            s.Append("if (curdy.length==1) {curdy = \"0\"+curdy}\n");
            s.Append("var curmn = mobj.options[mobj.selectedIndex].value\n");
            s.Append("if (curmn.length==1) {curmn = \"0\"+curmn}\n");
            s.Append("var curyr = yobj.options[yobj.selectedIndex].value\n");
            s.Append("if (selectdays > monthdays) {\n");
            s.Append("   for (var dlp=selectdays; dlp > monthdays; dlp--) {\n");
            s.Append("       dobj.options[dlp-1] = null }}\n");
            s.Append("else if (monthdays > selectdays) {\n");
            s.Append("   for (var dlp=selectdays; dlp < monthdays; dlp++) {\n");
            s.Append("       dobj.options[dlp] = new Option(dlp+1,dlp+1) }}\n");
            s.Append("if (curdy > monthdays) {\n");
            s.Append("   dobj.options[monthdays-1].selected = true\n");
            s.Append("   curdy = monthdays }\n");
            s.Append("var curdateconv = curmn+\"/\"+curdy+\"/\"+curyr\n");
            s.Append("if (datemode==1) {\n");
            s.Append("   var curdate = curmn+\"/\"+curdy+\"/\"+curyr }\n");
            s.Append("else if (datemode==2) {\n");
            s.Append("   var curdate = curdy+\"/\"+curmn+\"/\"+curyr }\n");
            s.Append("else if (datemode==3) {\n");
            s.Append("   var curdate = curyr+curmn+curdy }\n");
            s.Append("else if (datemode==4) {\n");
            s.Append("   var cdate = new Date(curyr,curmn-1,curdy)\n");
            s.Append("   var curdate = cdate.toGMTString() }\n");
            s.Append("hobj.value = curdate\n");
            s.Append("hobjconv.value = curdateconv\n");
            s.Append("}\n");
            s.Append("</SCRIPT>\n");
            s.Append("\n");
	
	    string CloseWindow;
 
            CloseWindow = "alert('Hello World')";
 
            ScriptManager.RegisterStartupScript(this,this.GetType(), "CloseWindow", CloseWindow, true);
 
            // Add the Script to the Page 
          //  this.Page.ClientScript.RegisterClientScriptBlock("mm_datepicker", s.ToString());
        
        }
 
    }
}

Open in new window

Avatar of TheMegaLoser
TheMegaLoser
Flag of Sweden image

Have you added a reference to System.Web.Extensions in you project?
Avatar of mathieu_cupryk

ASKER

hi there can u try getting this working with the days in the month.

http://www.truegeeks.com/asp/net/netcontrols.ASP
 

I am trying to use this in my page below. I have a scriptmanager in my master page.
 
Thanks I appreciate your help.
You're not exactly saying what the problem is but I gather that the javascript doesn't work for you?

Does it help if you change it to?

this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "mm_datepicker", s.ToString());
it works but the days don't work properly.
C:\inetpub\wwwroot\OmegaLove_CS\OL_Web\Bin>csc /t:library /out:mm_datepicker.dll
 /r:system.dll,system.web.dll, mm_datepicker.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.1434
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

mm_datepicker.cs(540,4): warning CS0618:
        'System.Web.UI.Page.RegisterClientScriptBlock(string, string)' is
        obsolete: 'The recommended alternative is
        ClientScript.RegisterClientScriptBlock(Type type, string key, string
        script). http://go.microsoft.com/fwlink/?linkid=14202'
Did you make the change I suggested above?

With that all is working fine when I test.
it gives me that warning.
if you go to omegalove.com u will see that the day does not get updated?
ASKER CERTIFIED SOLUTION
Avatar of TheMegaLoser
TheMegaLoser
Flag of Sweden image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
it is working how did u figure this out. Especially u are familar with master pages. Good trouble shooting
skills you've got.
also where should i keep a copy of the .cs in the project?

Very good job. Not many people can solve such a problem.
just a quick question if you goto omegalove.com
I get this error:
Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Didn't you make a separate assebmly for this control? Keep the code in that project only.

Since you received a javascript error I tried running the page in Firefox with the tool Firebug active. There I understood that the name of the control was to complex. .NET creates a name by concatenating all the levels of the control names to keep every name unique.

From there it was all about finding an alternative working solution.

The reason you get the error above is in the error message on the page:

The type 'mm_date.datepicker' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\b96e3816\231cefd9\assembly\dl3\204f5f7c\af1738f8_65fbc801\mm_datepicker.DLL' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\b96e3816\231cefd9\assembly\dl3\57a7d4fa\aa23afbb_84fac801\mm_date.DLL'

You have two assemblies referenced in your project containing the same control. Delete one of them and it should work fine. Remember to clean up the site on the server too.
ok, what is the best way to clean things on the server.
Just remove the old files.