How to access ASP.NET Calendar control from javascript?

B

Ben

I have a javascript code in the ASP.NET page.
I want to access Calendar control that is inside ASP page and is "run
at server".

I try to use following code but it doesn't work.

<script language="javascript">
function valSubmit()
{
document.getElementById("Calendar1").style.visibility =
'visible';
}
</script>

I got following error:

ERROR: Object required

Could anyone give a suggestion?

Thanks,
Ben
 
E

Edwin Knoppert

The calendar's UNIQUEID might differ on render try :

document.getElementById('<%=Calender1.uniqueid%>').style.visibility
='visible';

(You might need to modify to make it work)
 
G

Guest

Better to use ClientID instead of UniqueID - uniqueId names controls with a
'.' as a seperator instead of a '_'.
 
B

Ben

Hi Edwin,

The reason that I want to addess Calendar control in Javascript is
because I want to show and hide Calendar control without refreshing ASP
page.
I have a lot of database controls link to gridviews. Refreshing page
will take a long time.

Thanks,
Ben
 
K

Ken Cox [Microsoft MVP]

Are you sure you're getting the right ID for the Calendar? If it's inside a
container control, it might have a different prefix. Here's a way to get the
ID for sure.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
ClientScript.RegisterClientScriptBlock _
(Me.GetType(), "cal", "function
valSubmit(){document.getElementById('" & _
Calendar1.ClientID & "').style.visibility='hidden';}", True)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Hide Calendar</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:calendar id="Calendar1" runat="server"></asp:calendar>
<br />
<button onclick="valSubmit();return false;">Hide</button></div>
</form>
</body>
</html>
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top