弹出窗口需要引用内容控件中的文本框

发布于 2024-09-18 06:45:01 字数 1338 浏览 4 评论 0原文

我有一个位于内容控件内的链接。此链接调用一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小沫ゞ 2024-09-25 06:45:08

不要使用document.form1。使用document.getElementById(strField)。您还必须修复对 calendarPicker 的调用。 calendarPicker('<%= txtstart.ClientId %>');

不要将 JavaScript 放入 href 属性中。使用link.Attributes.Add("onclick", strLink)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文