views:

24

answers:

1

I have a link that is located inside a content control. This link calls a javascript function that opens a popup window containing a calendar and passes it the transformed id from the server of a textbox control using clientid. I need to be able to click on a date and have the popup close and insert the date into the textbox of the id I passed into the function which again, is located inside the content control.

This is the link in the content control:

<a title="Pick Date from Calendar" onclick="calendarPicker('form1.<%= txtstart.ClientId %>');" href="javascript:void(0);">

This is the javascript inside the masterpage:

<script type="text/javascript">
function calendarPicker(strField) {
    var strField = window.open('DatePicker.aspx?field=' + strField, 'calendarPopup', 'width=250,height=190,resizable=yes');
}

The calendar is a calendar control inside its own page and this is the codebehind:

Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs) Handles Calendar1.DayRender
        Dim link As New System.Web.UI.HtmlControls.HtmlGenericControl
Dim strLink As String
e.Cell.Controls.Clear()
link.TagName = "a"
link.InnerText = e.Day.DayNumberText
strLink = "JavaScript:window.opener.document." & Request.QueryString("Field") & ".value = '" & e.Day.Date & "'; window.close();"
link.Attributes.Add("href", strLink)
If (e.Day.IsSelected) Then
  link.Attributes.Add("style", Calendar1.SelectedDayStyle.ToString())
End If
e.Cell.Controls.Add(link)
End Sub

I should also mention the error I'm getting is:

window.opener.document.form1 is undefined

A: 

don't use document.form1. use document.getElementById(strField). you'll also have to fix your call to calendarPicker. calendarPicker('<%= txtstart.ClientId %>');

don't put javascript in the href property. use link.Attributes.Add("onclick", strLink)

lincolnk
Well if I weren't using a masterpage, everything works how I have it. I'll make the changes you suggest and see what works.
mjw06d
i'm making educated guesses since we don't know what your actual page looks like. post some html output if these suggestions don't help.
lincolnk