473,383 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Calendar Control ID unexpected result

Hi all,

I am trying to use a calendar server control which I have ID="Calendar1" in
the source code. What I am trying to do is emulate a JavaScript calendar
that was being used in an older ASP version of the application. The
javascript version worked nicely -- you click on a calendar.gif in an anchor
next to a textbox. The calender would pop up in a new window, you select the
date, the calendar window would close and the textbox would be populated
with the date. All without making a return trip to the server... very nice.

I was having trouble getting the old javascript to run by passing the code
from the anchor
href="javascript:show_calendar('document.GetElemen tById('txtUpDate2')');"
which was working fine in the ASP. I included the JS file that has the
show_calendar function.

So I am trying to use the VB 2005 Calendar control. I placed it in a User
Control, which appears in the Context area of a Master Page (like the rest
of the content). BTW, all the content is in the same user control, including
the just-added Calendar and the page uses a Master Page. Not too complicated
for a .NET app.

Well, I set the Calendar1 to style="visibility;hidden". Then I included
client side script
onclick="document.getElementById('Calendar1').styl e.visibility='visible'.

I got a clientside error about "Object Required".
When I looked at the source in the browser I see that the ID for the
Calendar is now:
ctl00_Content1_SearchEdit1_Calendar1
Wow. I didn't expect that. Also I haven't read anything anywhere about how
drastically the ID of an element or control can be changed at the browser.

1. Is there an explanation for that particular ID? The name of my User
Control is SearchEdit.ascx. Is there a way to predict what the clientside Id
will become when the control is nested in so many ways? Please direct me to
an article or MSDN discussion of that sort of thing, if anyone can.

2. Is there a way to use the Calendar control so that it actually does what
the old Javascript used to do? That was actually very cool.

Thanks......
Mar 8 '07 #1
7 2345

to insure uniqueness the id includes it parents control id. all control
have a property called ClientID that is the id that will be rendered.

-- bruce (sqlwork.com)
John Kotuby wrote:
Hi all,

I am trying to use a calendar server control which I have ID="Calendar1" in
the source code. What I am trying to do is emulate a JavaScript calendar
that was being used in an older ASP version of the application. The
javascript version worked nicely -- you click on a calendar.gif in an anchor
next to a textbox. The calender would pop up in a new window, you select the
date, the calendar window would close and the textbox would be populated
with the date. All without making a return trip to the server... very nice.

I was having trouble getting the old javascript to run by passing the code
from the anchor
href="javascript:show_calendar('document.GetElemen tById('txtUpDate2')');"
which was working fine in the ASP. I included the JS file that has the
show_calendar function.

So I am trying to use the VB 2005 Calendar control. I placed it in a User
Control, which appears in the Context area of a Master Page (like the rest
of the content). BTW, all the content is in the same user control, including
the just-added Calendar and the page uses a Master Page. Not too complicated
for a .NET app.

Well, I set the Calendar1 to style="visibility;hidden". Then I included
client side script
onclick="document.getElementById('Calendar1').styl e.visibility='visible'.

I got a clientside error about "Object Required".
When I looked at the source in the browser I see that the ID for the
Calendar is now:
ctl00_Content1_SearchEdit1_Calendar1
Wow. I didn't expect that. Also I haven't read anything anywhere about how
drastically the ID of an element or control can be changed at the browser.

1. Is there an explanation for that particular ID? The name of my User
Control is SearchEdit.ascx. Is there a way to predict what the clientside Id
will become when the control is nested in so many ways? Please direct me to
an article or MSDN discussion of that sort of thing, if anyone can.

2. Is there a way to use the Calendar control so that it actually does what
the old Javascript used to do? That was actually very cool.

Thanks......

Mar 8 '07 #2
"John Kotuby" <jo***@powerlist.comwrote in message
news:uS**************@TK2MSFTNGP05.phx.gbl...
href="javascript:show_calendar('document.GetElemen tById('txtUpDate2')');"
That's unlikely to work for three reasons:

1) Your single quotes and double quotes are inconsistent...

2) You mention that this is in a MasterPage, so the client-side ID of
txtUpdate2 will have been modified...

3) JavaScript, like C#, is case-sensitive, so GetElementById needs to be
getElementById...

href=show_calendar('document.GetElementById("<%=tx tUpDate2.ClientID%>")');
Mar 8 '07 #3
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ea**************@TK2MSFTNGP03.phx.gbl...
3) JavaScript, like C#, is case-sensitive, so GetElementById needs to be
getElementById...

href=show_calendar('document.GetElementById("<%=tx tUpDate2.ClientID%>")');
Therefore:
href=show_calendar('document.getElementById("<%=tx tUpDate2.ClientID%>")');

Sorry - hit the Enter button just too soon...-)
Mar 8 '07 #4
Thanks Bruce

"bruce barker" <no****@nospam.comwrote in message
news:Oe**************@TK2MSFTNGP05.phx.gbl...
>
to insure uniqueness the id includes it parents control id. all control
have a property called ClientID that is the id that will be rendered.

-- bruce (sqlwork.com)
John Kotuby wrote:
>Hi all,

I am trying to use a calendar server control which I have ID="Calendar1"
in the source code. What I am trying to do is emulate a JavaScript
calendar that was being used in an older ASP version of the application.
The javascript version worked nicely -- you click on a calendar.gif in an
anchor next to a textbox. The calender would pop up in a new window, you
select the date, the calendar window would close and the textbox would be
populated with the date. All without making a return trip to the
server... very nice.

I was having trouble getting the old javascript to run by passing the
code from the anchor
href="javascript:show_calendar('document.GetEleme ntById('txtUpDate2')');"
which was working fine in the ASP. I included the JS file that has the
show_calendar function.

So I am trying to use the VB 2005 Calendar control. I placed it in a User
Control, which appears in the Context area of a Master Page (like the
rest of the content). BTW, all the content is in the same user control,
including the just-added Calendar and the page uses a Master Page. Not
too complicated for a .NET app.

Well, I set the Calendar1 to style="visibility;hidden". Then I included
client side script
onclick="document.getElementById('Calendar1').sty le.visibility='visible'.

I got a clientside error about "Object Required".
When I looked at the source in the browser I see that the ID for the
Calendar is now:
ctl00_Content1_SearchEdit1_Calendar1
Wow. I didn't expect that. Also I haven't read anything anywhere about
how drastically the ID of an element or control can be changed at the
browser.

1. Is there an explanation for that particular ID? The name of my User
Control is SearchEdit.ascx. Is there a way to predict what the clientside
Id will become when the control is nested in so many ways? Please direct
me to an article or MSDN discussion of that sort of thing, if anyone can.

2. Is there a way to use the Calendar control so that it actually does
what the old Javascript used to do? That was actually very cool.

Thanks......


Mar 9 '07 #5
Thanks Mark,

I am trying the syntax at the bottom of your reply, but the VS 2005 IDE is
giving me an error about non-matching quotes.
Note: I am copying the actual source that is being shown on screen into this
post.

When I place quotes around the href attribute in the source code...

href="javascript:show_calendar('document.getElemen tById("<%=txtCreateDate.ClientID%>")')"

So that the VStudio error goes away (and the line
<%=txtCreateDate.ClientID%shows up in red)

I get the browser error...

Public member 'ClientID' on type 'String' not found.

pointing to the line in the browser ...
<a
href="javascript:show_calendar('document.getElemen tById("<%=txtCreateDate.ClientID%>")')"
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:Oe*************@TK2MSFTNGP04.phx.gbl...
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ea**************@TK2MSFTNGP03.phx.gbl...
>3) JavaScript, like C#, is case-sensitive, so GetElementById needs to be
getElementById...

href=show_calendar('document.GetElementById("<%=t xtUpDate2.ClientID%>")');

Therefore:
href=show_calendar('document.getElementById("<%=tx tUpDate2.ClientID%>")');

Sorry - hit the Enter button just too soon...-)



Mar 9 '07 #6
"John Kotuby" <jo***@powerlist.comwrote in message
news:ei*************@TK2MSFTNGP04.phx.gbl...
I am trying the syntax at the bottom of your reply, but the VS 2005 IDE is
giving me an error about non-matching quotes.
Note: I am copying the actual source that is being shown on screen into
this post.

When I place quotes around the href attribute in the source code...

href="javascript:show_calendar('document.getElemen tById("<%=txtCreateDate.ClientID%>")')"

So that the VStudio error goes away (and the line
<%=txtCreateDate.ClientID%shows up in red)

I get the browser error...

Public member 'ClientID' on type 'String' not found.

pointing to the line in the browser ...
<a
href="javascript:show_calendar('document.getElemen tById("<%=txtCreateDate.ClientID%>")')"
Hmm - you might be able to fix it by escaping one of the pairs of quotes
e.g. \'.....\'

Another option, though a bit of a kludge, might be something like:

var objCreateDate = document.getElementById('<%=txtCreateDate.ClientID %>');
href="show_calendar(objCreateDate)";

You seem to keep putting "javascript:" back in...
Also, you seem to keep removing the semi-colon from the end of the line...
Mar 9 '07 #7
Thanks Mark...
I keep putting the javascript: part back in because that is what was in the
original ASP and I thought it was necessary to use as the value for the
href= whereas the onclick= attribute allows direct calling of the javascript
function. I understand that if I include the Runat="Server" that the syntax
would need to change to OnClientClick=.

Here is some code in context as viewed from the server side error message:
----------------------------
Exception Details: System.MissingMemberException: Public member 'ClientID'
on type 'String' not found.

<td nowrap="nowrap">
Line 400: <input type="text" class="smallCbo2"
name="txtCreateDate" id="txtCreateDate" value="<%=txtCreateDate%>" />
Line 401: <a
href="javascript:show_calendar('document.getElemen tById('<%=txtCreateDate.ClientID%>')');"
onmouseover="window.status='Date Picker';return true;"
Line 402: onmouseout="window.status='';return
true;">
Line 403: <img alt="Calendar"
src="../../images/show-calendar.gif" width="17" height="16" border="0"
/></a>
---------------------------------

Note that I have not declared these particular controls as runat=server.
This page is a very complicated mixture of controls for putting together a
long search query for SQL Server. For now I am trying to port most of the
markup as-is until I understand better how the original Author of the ASP
program made it work. Then when time allows, convert the coding to primarily
server controls in ASP.NET 2.0. The page renders fine until I try running
the clientsidejavascript.

Note that line 400 value=<%=txtCreateDate %reneders fine and does not
cause an error.

Oops... I may now see what's happening. I had created a VB string variable
txtCreateDate which happens to have the same name as the ID of the input
control. I will change the ID of the input control to txtCreateDate1 and see
if that helps.

I am also wondering if using the ID of the control for in-line VB is correct
syntax as in ControlId.ClientId. Most of the Online help shows an example of
first declaring an Instance of the control in order to get to the ControlID
property. Sure would be nice if the short-hand version worked.

I guess I will find out soon. I am also going to try assembling the strings
into a variable as you suggested. Maybe in the Code Behind in Page_Init.

.... John
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ei**************@TK2MSFTNGP03.phx.gbl...
"John Kotuby" <jo***@powerlist.comwrote in message
news:ei*************@TK2MSFTNGP04.phx.gbl...
>I am trying the syntax at the bottom of your reply, but the VS 2005 IDE
is giving me an error about non-matching quotes.
Note: I am copying the actual source that is being shown on screen into
this post.

When I place quotes around the href attribute in the source code...

href="javascript:show_calendar('document.getEleme ntById("<%=txtCreateDate.ClientID%>")')"

So that the VStudio error goes away (and the line
<%=txtCreateDate.ClientID%shows up in red)

I get the browser error...

Public member 'ClientID' on type 'String' not found.

pointing to the line in the browser ...
<a
href="javascript:show_calendar('document.getEleme ntById("<%=txtCreateDate.ClientID%>")')"

Hmm - you might be able to fix it by escaping one of the pairs of quotes
e.g. \'.....\'

Another option, though a bit of a kludge, might be something like:

var objCreateDate =
document.getElementById('<%=txtCreateDate.ClientID %>');
href="show_calendar(objCreateDate)";

You seem to keep putting "javascript:" back in...
Also, you seem to keep removing the semi-colon from the end of the line...

Mar 9 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Charles | last post by:
Hello, I would like for my users to have a calendar control only when needed. IE button click for the control to appear and then once the date is selected. Populate a text box and the calendar...
5
by: Miguel Dias Moura | last post by:
Hello, i am trying to create a .css file with several styles and apply them to the calendar control so i can change the look of: 1. Text Type and Format (Bold, Underline, etc) 2. Background...
2
by: Caesar Augustus | last post by:
First, let me start by saying my asp.net experience is still in it's infancy so please bare with me as I try to explain my situation. I have created a single page that with the use of many...
1
by: MattB | last post by:
Hi. I posted yesterday about being able to get to Day.IsSelecteable from outside the calendar's DayRender event. I never figured that out, so I found another way to do what I needed by...
0
by: sakieboy | last post by:
I'm working with ASP.Net 1.1. I have a user control that displays a javascript/DHTML calendar (because the normal calendar is clunky-real estate issue). I am using Microsoft.Web.UI.Webcontrols for...
0
by: jphelan | last post by:
After opening and clicking on the popup calendar command control button, "fdlgCal"; I click on a given date. The date is suppose to then appear in a date field next to the control. Instead, I get...
4
by: ShyGuy | last post by:
A while back I had found a link to a popup calendar that had a small button that was placed to the right of any text box. By clicking on the icon and selecting a date the text box was updated with...
3
by: thorpk | last post by:
I posted this problem earlier in the month and some one decided it was better to change the subject and ask a completely different question. I am therefore reposting. I am hoping some one can...
0
by: mathewgk80 | last post by:
HI all, I am having popup calendar Javascript code. But i dont know how it is connecting to asp.net code.. I am using asp.net,c#.net and also using 3tier architecture with master page.... I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.