C# Newbie, passing variables between Web Pages

  • Thread starter Thread starter Simon W
  • Start date Start date
S

Simon W

Hi,

I am trying to do something that I presume is very simple but am
struggling to do it. Any help would be appreciated.

I have a Web form which requires a Date field to be filled in. I am
using the ASP Calender Control to do this in a spearate window.
However I want to return the chosen Date to a field in the first
browser window e.g.

1) Webform1 opens Calenderform1
2) User Selects a Date and presses OK
3) The Date is passed back to a WebControl TextBox in Webform1
4) Calenderform1 is closed.

I am struggling with points 3 and 4.

Thanks in advance for any help.

Regards

Simon
 
Simon,

When you open the new window, it is through a javascript call. When you
make the call, you need to pass a reference to the parent window, or at
least, the textbox which has the date. Then, when you press ok in the
calendar window, you can set the text of the textbox to the date (all of
this is through javascript, not through C#). It's easy enough to give your
main window a name, and then get the window through the windows collection
(I believe that is what it is called) in javascript.

Hope this helps.
 
It's by no means obvious if your new to this.
Make sure when you call the calendar, you do something like this.

----- Parent.aspx
<script type="text/javascript">

function GetDate(CtrlName)
{
ChildWindow = window.open('Calendar.aspx?FormName=' +
document.forms[0].name + '&CtrlName=' + CtrlName, "PopUpCalendar",
"width=306,height=450,top=100,left=120,toolbars=no,scrollbars=no,status=no,resizable=no").focus();
}

</script>

Then reference this function in an onclick of some button where you call
"javascript:GetDate('TextBoxDate')"
where TextBoxDate is the name of your textbox to populate


Now in your calendar popup...
Onclick attribute for the OK button should call this clientside script

----- Calendar.aspx
<script type="text/javascript">
function ReturnDate()
{

if ( window.opener )
{
window.opener.document.forms["<%= strFormName
%>"].elements["<%= strCtrlName %>"].value = "<%= strSelectedDate %>";
window.opener.location.href = window.opener.location.href;
}
else
{
// IE 5.0 and less...
alert ("The current browser you are running does not support
the javascript function required to select a date/time from this dialog.");
}
window.close();

}

</script>


Need any help let me know.

Dan.
 
Nicholas and Dan,

Thanks for the advise on this with your help and a little lucky
further searching I have managed to solve the problem.

Macromedia provide a tutorial on this very thing, so a combination of
your advice and this has allowed me to achieve what I was looking for.

The link below takes you to the Macromedia site.

http://www.macromedia.com/devnet/mx/dreamwaever/articles/aspnet_calender_03.html

Thanks again

Simon

Dan Bass said:
It's by no means obvious if your new to this.
Make sure when you call the calendar, you do something like this.

----- Parent.aspx
<script type="text/javascript">

function GetDate(CtrlName)
{
ChildWindow = window.open('Calendar.aspx?FormName=' +
document.forms[0].name + '&CtrlName=' + CtrlName, "PopUpCalendar",
"width=306,height=450,top=100,left=120,toolbars=no,scrollbars=no,status=no,resizable=no").focus();
}

</script>

Then reference this function in an onclick of some button where you call
"javascript:GetDate('TextBoxDate')"
where TextBoxDate is the name of your textbox to populate


Now in your calendar popup...
Onclick attribute for the OK button should call this clientside script

----- Calendar.aspx
<script type="text/javascript">
function ReturnDate()
{

if ( window.opener )
{
window.opener.document.forms["<%= strFormName
%>"].elements["<%= strCtrlName %>"].value = "<%= strSelectedDate %>";
window.opener.location.href = window.opener.location.href;
}
else
{
// IE 5.0 and less...
alert ("The current browser you are running does not support
the javascript function required to select a date/time from this dialog.");
}
window.close();

}

</script>


Need any help let me know.

Dan.



Simon W said:
Hi,

I am trying to do something that I presume is very simple but am
struggling to do it. Any help would be appreciated.

I have a Web form which requires a Date field to be filled in. I am
using the ASP Calender Control to do this in a spearate window.
However I want to return the chosen Date to a field in the first
browser window e.g.

1) Webform1 opens Calenderform1
2) User Selects a Date and presses OK
3) The Date is passed back to a WebControl TextBox in Webform1
4) Calenderform1 is closed.

I am struggling with points 3 and 4.

Thanks in advance for any help.

Regards

Simon
 
Back
Top