Problem using Master & Content pages with Calendar pop-up

Discussion in 'ASP .Net' started by jediknight, Aug 28, 2007.

  1. jediknight

    jediknight Guest

    I have a simple project where there is a master page called
    MasterPage.master and some webforms which are content pages. I also
    have a usercontrol which is a simple calendar control popup.
    The folder structure is as follows:

    Test Folder
    Test.aspx (normal webform)
    Test2.aspx (content page)

    ctlCalendar.ascx
    Default.aspx (normal webform)
    Default2.aspx (content page)
    MasterPage.master
    Web.Config

    Both Test.apsx and Test2.aspx use the calendar control.
    Default.aspx redirects to Test.aspx and Default2.aspx redirect to
    Test2.aspx.

    The problem I'm having is that when I set Default.aspx as the startup
    page, the calendar control works fine.

    When I use Default2.aspx (content page) as the start up I get an error

    Error: 'CtlCalendar1_pnlCalendar' is undefined

    in the explorer status bar.

    ctlCalendar Code is as follows:

    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    this.TextBox1.Text = System.DateTime.Now.ToShortDateString();
    this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION:
    absolute");
    }
    else
    {
    string id =
    Page.Request.Form["__EVENTTARGET"].Substring(0,Page.Request.Form["__EVENTTARGET"].IndexOf(":"));
    if (id != this.ID)
    this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION:
    absolute");
    else
    this.pnlCalendar.Attributes.Add("style","POSITION: absolute");
    }
    Page.RegisterClientScriptBlock("Script_Panel" + this.ID, "<script>
    function On"+this.ID+"Click() { if("+this.ID
    +"_pnlCalendar.style.display == \"none\") "+this.ID
    +"_pnlCalendar.style.display = \"\"; else "+this.ID
    +"_pnlCalendar.style.display = \"none\"; } </script>");

    this.Button1.Attributes.Add("OnClick","On"+this.ID+"Click()");
    }



    private void Calendar1_SelectionChanged(object sender,
    System.EventArgs e)
    {
    this.TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
    this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION:
    absolute");
    }
     
    jediknight, Aug 28, 2007
    #1
    1. Advertising

  2. What you're seeing is a JavaScript error, caused by using the ID of the
    Control rather than the ClientID of the Control. The ClientID of a Control
    is designed to always be unique in the client HTML document, and this is
    done by using the nested position of the Control inside other Controls. The
    ID is the server-side ID of the Control used for server-side processing.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP

    DSI PrintManager, Miradyne Component Libraries:
    http://www.miradyne.net

    "jediknight" <> wrote in message
    news:...
    >I have a simple project where there is a master page called
    > MasterPage.master and some webforms which are content pages. I also
    > have a usercontrol which is a simple calendar control popup.
    > The folder structure is as follows:
    >
    > Test Folder
    > Test.aspx (normal webform)
    > Test2.aspx (content page)
    >
    > ctlCalendar.ascx
    > Default.aspx (normal webform)
    > Default2.aspx (content page)
    > MasterPage.master
    > Web.Config
    >
    > Both Test.apsx and Test2.aspx use the calendar control.
    > Default.aspx redirects to Test.aspx and Default2.aspx redirect to
    > Test2.aspx.
    >
    > The problem I'm having is that when I set Default.aspx as the startup
    > page, the calendar control works fine.
    >
    > When I use Default2.aspx (content page) as the start up I get an error
    >
    > Error: 'CtlCalendar1_pnlCalendar' is undefined
    >
    > in the explorer status bar.
    >
    > ctlCalendar Code is as follows:
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > if (!Page.IsPostBack)
    > {
    > this.TextBox1.Text = System.DateTime.Now.ToShortDateString();
    > this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION:
    > absolute");
    > }
    > else
    > {
    > string id =
    > Page.Request.Form["__EVENTTARGET"].Substring(0,Page.Request.Form["__EVENTTARGET"].IndexOf(":"));
    > if (id != this.ID)
    > this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION:
    > absolute");
    > else
    > this.pnlCalendar.Attributes.Add("style","POSITION: absolute");
    > }
    > Page.RegisterClientScriptBlock("Script_Panel" + this.ID, "<script>
    > function On"+this.ID+"Click() { if("+this.ID
    > +"_pnlCalendar.style.display == \"none\") "+this.ID
    > +"_pnlCalendar.style.display = \"\"; else "+this.ID
    > +"_pnlCalendar.style.display = \"none\"; } </script>");
    >
    > this.Button1.Attributes.Add("OnClick","On"+this.ID+"Click()");
    > }
    >
    >
    >
    > private void Calendar1_SelectionChanged(object sender,
    > System.EventArgs e)
    > {
    > this.TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
    > this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION:
    > absolute");
    > }
    >
     
    Kevin Spencer, Aug 28, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    3,278
    PeterKellner
    May 16, 2006
  2. Replies:
    0
    Views:
    757
  3. vikramp
    Replies:
    3
    Views:
    769
    vikramp
    Oct 13, 2006
  4. jobs
    Replies:
    1
    Views:
    486
    clintonG
    Dec 13, 2006
  5. sjsean

    master pages and content pages

    sjsean, Aug 1, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    474
    Scott M.
    Aug 1, 2009
Loading...

Share This Page