弹出窗口需要引用内容控件中的文本框
我有一个位于内容控件内的链接。此链接调用一个 JavaScript 函数,该函数打开一个包含日历的弹出窗口,并使用 clientid 将来自文本框控件的服务器的转换后的 ID 传递给它。我需要能够单击日期并关闭弹出窗口,并将日期插入到我传递到函数中的 id 的文本框中,该函数再次位于内容控件内。
这是内容控件中的链接:
<a title="Pick Date from Calendar" onclick="calendarPicker('form1.<%= txtstart.ClientId %>');" href="javascript:void(0);">
这是母版页内的 javascript:
<script type="text/javascript">
function calendarPicker(strField) {
var strField = window.open('DatePicker.aspx?field=' + strField, 'calendarPopup', 'width=250,height=190,resizable=yes');
}
日历是其自己页面内的日历控件,这是隐藏的代码:
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
我还应该提到我收到的错误是:
window.opener.document.form1 is undefined
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用
document.form1
。使用document.getElementById(strField)
。您还必须修复对calendarPicker
的调用。calendarPicker('<%= txtstart.ClientId %>');
不要将 JavaScript 放入
href
属性中。使用link.Attributes.Add("onclick", strLink)don't use
document.form1
. usedocument.getElementById(strField)
. you'll also have to fix your call tocalendarPicker
.calendarPicker('<%= txtstart.ClientId %>');
don't put javascript in the
href
property. uselink.Attributes.Add("onclick", strLink)