Problem using Master & Content pages with Calendar pop-up

J

jediknight

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");
}
 
K

Kevin Spencer

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top