Help with calender control

G

Guest

Hi,
I am trying to create a popup calender so a user can click on a button on
the main form, a calender will then popup, the user will select a date and
then click ok on the popup. The date will then be passed back to the main
form and populate a textbox. I tried two options. None worked.

First. I used the popup calender form the time tracker starter kit. On my
page I have an image buton. In the click event I have the foll code


btnFrom.Attributes.Add("onclick", "OpenCalendar('txtfrom', true);")

In the <HEAD> section of the form I have the foll


<script language="javascript" src="script.js" type="text/javascript"></script>

This is the javascript

var popUp;

function OpenCalendar(idname, postBack)
{
popUp = window.open('testCal.aspx?formname=' + document.forms[0].name +
'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value
+ '&postBack=' + postBack,
'popupcal',
'width=165,height=208,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
eval('var theform = document.' + formName + ';');
popUp.close();
theform.elements[id].value = newDate;
if (postBack)
__doPostBack(id,'');
}


I get the foll error when I try to load the popup form the button click


"A runtime error has occured.
Do you wish to debug?

Line 5
Error: 'document.forms(0).elements[...].value' is null or not an object.

Second OPTION

I created a form called main with an image button and placed the foll code
on load

btn1.Attributes.Add("onclick", "var strReturn;
strReturn=window.showModalDialog('popup.aspx',null,'status:no;dialogWidth:250px;dialogHeight:225px;dialogHide:true;help:no;scroll:no');if
(strReturn != null) document.getElementById('txtStartDate').value=strReturn;")

This popups up form with a calender. It pops up fine, however, when you
click on a date or anything it pops up another page

with javascript:__doPostBack('calDate','1809') in the address bar and 'page
not found' in the body.

Any ideas?
 
B

Bryce Budd

This article will give you the answers you seek.

http://aspnet.4guysfromrolla.com/articles/030202-1.aspx

Bryce

Chris said:
Hi,
I am trying to create a popup calender so a user can click on a button on
the main form, a calender will then popup, the user will select a date and
then click ok on the popup. The date will then be passed back to the main
form and populate a textbox. I tried two options. None worked.

First. I used the popup calender form the time tracker starter kit. On my
page I have an image buton. In the click event I have the foll code


btnFrom.Attributes.Add("onclick", "OpenCalendar('txtfrom', true);")

In the <HEAD> section of the form I have the foll


<script language="javascript" src="script.js"
type="text/javascript"> said:
This is the javascript

var popUp;

function OpenCalendar(idname, postBack)
{
popUp = window.open('testCal.aspx?formname=' + document.forms[0].name +
'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value
+ '&postBack=' + postBack,
'popupcal',
'width=165,height=208,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
eval('var theform = document.' + formName + ';');
popUp.close();
theform.elements[id].value = newDate;
if (postBack)
__doPostBack(id,'');
}


I get the foll error when I try to load the popup form the button click


"A runtime error has occured.
Do you wish to debug?

Line 5
Error: 'document.forms(0).elements[...].value' is null or not an object.

Second OPTION

I created a form called main with an image button and placed the foll code
on load

btn1.Attributes.Add("onclick", "var strReturn;
strReturn=window.showModalDialog('popup.aspx',null,'status:no;dialogWidth:25
0px;dialogHeight:225px;dialogHide:true;help:no;scroll:no');if
(strReturn != null) document.getElementById('txtStartDate').value=strReturn;")

This popups up form with a calender. It pops up fine, however, when you
click on a date or anything it pops up another page

with javascript:__doPostBack('calDate','1809') in the address bar and 'page
not found' in the body.

Any ideas?
 
G

Guest

Hi,
It really doesn't. I need to know how to execute my javascript from a button
and not a hyperlink. My script works when I use a hyperlink button like

<a
href="javascript:calendar_window=window.open('/calendar.aspx?formname=frmCalendar.txtDate','calendar_window','width=154,height=188');calendar_window.focus()">

But if I try to use it from a button by setting the properties at form load
like

btnFrom.Attributes.Add("onclick", "OpenCalendar('txtfrom', true)")

I am getting the error. There must be a way to call a javascript from a
button!

Thanks



Bryce Budd said:
This article will give you the answers you seek.

http://aspnet.4guysfromrolla.com/articles/030202-1.aspx

Bryce

Chris said:
Hi,
I am trying to create a popup calender so a user can click on a button on
the main form, a calender will then popup, the user will select a date and
then click ok on the popup. The date will then be passed back to the main
form and populate a textbox. I tried two options. None worked.

First. I used the popup calender form the time tracker starter kit. On my
page I have an image buton. In the click event I have the foll code


btnFrom.Attributes.Add("onclick", "OpenCalendar('txtfrom', true);")

In the <HEAD> section of the form I have the foll


<script language="javascript" src="script.js"
type="text/javascript"> said:
This is the javascript

var popUp;

function OpenCalendar(idname, postBack)
{
popUp = window.open('testCal.aspx?formname=' + document.forms[0].name +
'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value
+ '&postBack=' + postBack,
'popupcal',
'width=165,height=208,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
eval('var theform = document.' + formName + ';');
popUp.close();
theform.elements[id].value = newDate;
if (postBack)
__doPostBack(id,'');
}


I get the foll error when I try to load the popup form the button click


"A runtime error has occured.
Do you wish to debug?

Line 5
Error: 'document.forms(0).elements[...].value' is null or not an object.

Second OPTION

I created a form called main with an image button and placed the foll code
on load

btn1.Attributes.Add("onclick", "var strReturn;
strReturn=window.showModalDialog('popup.aspx',null,'status:no;dialogWidth:25
0px;dialogHeight:225px;dialogHide:true;help:no;scroll:no');if
(strReturn != null) document.getElementById('txtStartDate').value=strReturn;")

This popups up form with a calender. It pops up fine, however, when you
click on a date or anything it pops up another page

with javascript:__doPostBack('calDate','1809') in the address bar and 'page
not found' in the body.

Any ideas?
 
B

Bryce Budd

This works fine for me.....see if it help

Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false"
Inherits="FreeTextBoxTest.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
var popUp;

function OpenCalendar(idname, postBack)
{
popUp = window.open('Webform1.aspx?formname=' + document.forms[0].name +
'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value +
'&postBack=' + postBack, 'popupcal',
'width=165,height=208,left=200,top=250,location=yes,resizable=yes');
popUp.focus();
}

</script>
</HEAD>
<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">
<input type="hidden" name="myTest" value="This is my test data" >
<asp:ImageButton ID="imgBtn_Test" Runat="server"
ImageUrl="images/btn_FindApp.gif" />

</form>

</body>
</HTML>

Code Behind

private void Page_Load(object sender, System.EventArgs e)

{

imgBtn_Test.Attributes["onclick"] = "javascript:OpenCalendar('myTest',
false);";

}


Chris said:
Hi,
It really doesn't. I need to know how to execute my javascript from a button
and not a hyperlink. My script works when I use a hyperlink button like

<a
href="javascript:calendar_window=window.open('/calendar.aspx?formname=frmCal
endar.txtDate','calendar_window','width=154,height=188');calendar_window.foc
us()">

But if I try to use it from a button by setting the properties at form load
like

btnFrom.Attributes.Add("onclick", "OpenCalendar('txtfrom', true)")

I am getting the error. There must be a way to call a javascript from a
button!

Thanks



Bryce Budd said:
This article will give you the answers you seek.

http://aspnet.4guysfromrolla.com/articles/030202-1.aspx

Bryce

Chris said:
Hi,
I am trying to create a popup calender so a user can click on a button on
the main form, a calender will then popup, the user will select a date and
then click ok on the popup. The date will then be passed back to the main
form and populate a textbox. I tried two options. None worked.

First. I used the popup calender form the time tracker starter kit. On my
page I have an image buton. In the click event I have the foll code


btnFrom.Attributes.Add("onclick", "OpenCalendar('txtfrom', true);")

In the <HEAD> section of the form I have the foll


<script language="javascript" src="script.js"
type="text/javascript"> said:
This is the javascript

var popUp;

function OpenCalendar(idname, postBack)
{
popUp = window.open('testCal.aspx?formname=' + document.forms[0].name +
'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value
+ '&postBack=' + postBack,
'popupcal',
'width=165,height=208,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
eval('var theform = document.' + formName + ';');
popUp.close();
theform.elements[id].value = newDate;
if (postBack)
__doPostBack(id,'');
}


I get the foll error when I try to load the popup form the button click


"A runtime error has occured.
Do you wish to debug?

Line 5
Error: 'document.forms(0).elements[...].value' is null or not an object.

Second OPTION

I created a form called main with an image button and placed the foll code
on load

btn1.Attributes.Add("onclick", "var strReturn;
strReturn=window.showModalDialog('popup.aspx',null,'status:no;dialogWidth:25
0px;dialogHeight:225px;dialogHide:true;help:no;scroll:no');if
(strReturn != null) document.getElementById('txtStartDate').value=strReturn;")

This popups up form with a calender. It pops up fine, however, when you
click on a date or anything it pops up another page

with javascript:__doPostBack('calDate','1809') in the address bar and 'page
not found' in the body.

Any ideas?
 
G

Guest

Hi,
It works fine but why does the popup calender takes that long to load? The
one from the Time Tracker Starter Kit pops up very fast even on my local
machine. Any ideas?

Thanks

Bryce Budd said:
This works fine for me.....see if it help

Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false"
Inherits="FreeTextBoxTest.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
var popUp;

function OpenCalendar(idname, postBack)
{
popUp = window.open('Webform1.aspx?formname=' + document.forms[0].name +
'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value +
'&postBack=' + postBack, 'popupcal',
'width=165,height=208,left=200,top=250,location=yes,resizable=yes');
popUp.focus();
}

</script>
</HEAD>
<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">
<input type="hidden" name="myTest" value="This is my test data" >
<asp:ImageButton ID="imgBtn_Test" Runat="server"
ImageUrl="images/btn_FindApp.gif" />

</form>

</body>
</HTML>

Code Behind

private void Page_Load(object sender, System.EventArgs e)

{

imgBtn_Test.Attributes["onclick"] = "javascript:OpenCalendar('myTest',
false);";

}


Chris said:
Hi,
It really doesn't. I need to know how to execute my javascript from a button
and not a hyperlink. My script works when I use a hyperlink button like

<a
href="javascript:calendar_window=window.open('/calendar.aspx?formname=frmCal
endar.txtDate','calendar_window','width=154,height=188');calendar_window.foc
us()">

But if I try to use it from a button by setting the properties at form load
like

btnFrom.Attributes.Add("onclick", "OpenCalendar('txtfrom', true)")

I am getting the error. There must be a way to call a javascript from a
button!

Thanks



Bryce Budd said:
This article will give you the answers you seek.

http://aspnet.4guysfromrolla.com/articles/030202-1.aspx

Bryce

Hi,
I am trying to create a popup calender so a user can click on a button on
the main form, a calender will then popup, the user will select a date and
then click ok on the popup. The date will then be passed back to the main
form and populate a textbox. I tried two options. None worked.

First. I used the popup calender form the time tracker starter kit. On my
page I have an image buton. In the click event I have the foll code


btnFrom.Attributes.Add("onclick", "OpenCalendar('txtfrom', true);")

In the <HEAD> section of the form I have the foll


<script language="javascript" src="script.js"
type="text/javascript"></script>

This is the javascript

var popUp;

function OpenCalendar(idname, postBack)
{
popUp = window.open('testCal.aspx?formname=' + document.forms[0].name +
'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value
+ '&postBack=' + postBack,
'popupcal',
'width=165,height=208,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
eval('var theform = document.' + formName + ';');
popUp.close();
theform.elements[id].value = newDate;
if (postBack)
__doPostBack(id,'');
}


I get the foll error when I try to load the popup form the button click


"A runtime error has occured.
Do you wish to debug?

Line 5
Error: 'document.forms(0).elements[...].value' is null or not an object.

Second OPTION

I created a form called main with an image button and placed the foll code
on load

btn1.Attributes.Add("onclick", "var strReturn;

strReturn=window.showModalDialog('popup.aspx',null,'status:no;dialogWidth:25
0px;dialogHeight:225px;dialogHide:true;help:no;scroll:no');if
(strReturn != null)
document.getElementById('txtStartDate').value=strReturn;")

This popups up form with a calender. It pops up fine, however, when you
click on a date or anything it pops up another page

with javascript:__doPostBack('calDate','1809') in the address bar and
'page
not found' in the body.

Any ideas?
 

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,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top