By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,954 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,954 IT Pros & Developers. It's quick & easy.

Help with calender control

P: n/a
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;d ialogHide:true;help:no;scroll:no');if
(strReturn != null) document.getElementById('txtStartDate').value=strR eturn;")

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?

Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
This article will give you the answers you seek.

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

Bryce

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
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;scr oll:no');if (strReturn != null) document.getElementById('txtStartDate').value=strR eturn;")
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?

Nov 19 '05 #2

P: n/a
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','calen dar_window','width=154,height=188');calendar_windo w.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" wrote:
This article will give you the answers you seek.

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

Bryce

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
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;scr oll:no');if
(strReturn != null)

document.getElementById('txtStartDate').value=strR eturn;")

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?


Nov 19 '05 #3

P: n/a
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=ye s,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" <Ch***@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
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" wrote:
This article will give you the answers you seek.

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

Bryce

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
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;scr oll:no');if
(strReturn != null)

document.getElementById('txtStartDate').value=strR eturn;")

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?


Nov 19 '05 #4

P: n/a
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" wrote:
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=ye s,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" <Ch***@discussions.microsoft.com> wrote in message
news:12**********************************@microsof t.com...
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" wrote:
This article will give you the answers you seek.

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

Bryce

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
> 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;scr oll:no');if
> (strReturn != null)
document.getElementById('txtStartDate').value=strR eturn;")
>
> 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?
>


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.