Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to pass the values to the textbox through window.opener

Status
Not open for further replies.

prasadalone

Programmer
Joined
Aug 15, 2002
Messages
87


I am calling cander.aspx page through javascript

i am using window.opener to set the values of the textbox
i think because my textbox is server control so that through calendar.aspx page i am not able to pass the values to the texbox is there any way to transfer the values from calendar.aspx page to the textbox on the calling page

<tr>
<td valign="top" width="30%">
Payment received Date</td>
<td valign="top" width="70%">
<asp:TextBox id="paymrecddate" runat="server" name="paymrecddate"></asp:TextBox>
<a href="javascript:calendar_window=window.open('/calendar.aspx?formname=frmCalendar.txtDate','calendar_window','width=154,height=188');calendar_window.focus()">Calendar </a></td>
</tr>

Following is the code for calendar.aspx page



<%@ Page Language="vb" %>
<script runat="server">

Private Sub Calendar1_SelectionChanged(sender As Object, e As System.EventArgs)
Dim strjscript as string = "<script language=""javascript"">"
strjscript = strjscript & "window.opener." & Httpcontext.Current.Request.Querystring("formname") & ".value = '" & Calendar1.SelectedDate & "';window.close();"
strjscript = strjscript & "</script" & ">" 'Don't Ask, Tool Bug
Literal1.text = strjscript

window.opener.document.forms[0].TextBox1.value

End Sub

Private Sub Calendar1_DayRender(sender As Object, e As System.Web.UI.WebControls.DayRenderEventArgs)
If e.Day.Date = datetime.now().tostring("d") Then
e.Cell.BackColor = System.Drawing.Color.LightGray
End If
End Sub

</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Choose a Date</title>
</head>
<body leftmargin="0" topmargin="0">
<form runat="server">
<asp:Calendar id="Calendar1" runat="server" Width="120" Height="60" ForeColor="#00000" BorderColor="#000000" FirstDayOfWeek="Monday" BackColor="#ffffff" SelectionMode="Day" DayNameFormat="FirstTwoLetters" showtitle="true" OnDayRender="Calendar1_dayrender" OnSelectionChanged="Calendar1_SelectionChanged">
<TitleStyle backcolor="#000080" forecolor="#ffffff" />
<NextPrevStyle backcolor="#000080" forecolor="#ffffff" />
<OtherMonthDayStyle forecolor="#c0c0c0" />
</asp:Calendar>
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</form>
</body>
</html>


 
This is how I did it. I created a hidden text field on the calendar.aspx page. Then I used some javascript (updateParent)on submit to transfer the value back to the main form. I'm using the parent-child relationship in DOM.

I have a button on the Calendar.aspx that submits the form.

I am opening Calendar.aspx in another window, similar to what you are doing.

There maybe more elegant solutions but I know this works...

This is the calendar.aspx page...
Code:
<SCRIPT LANGUAGE="JavaScript"><!--
function updateParent() {
    opener.document.Form1.txt_Begin_Date.value = document.childForm.txtBeginDate.value;
    
    self.close();
    return false;
}
<FORM runat="server" ID="childForm" onSubmit="return updateParent();">

private void cal_SelectionChanged(object sender, System.EventArgs e)
		{
			this.txtBeginDate.Value = this.cal.SelectedDate.ToShortDateString();
			
		}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top