dポイントプレゼントキャンペーン実施中!

以下の環境で開発を行っております。
Windows XP(Professional)
Visual Web Developer 2008 Express Edition
Internet Explorer 8

【質問】
FormView ではなくて Form から別画面でカレンダーを開き値を戻す事はできたのですが、FormView を使った画面からデータを戻すことができず、エラーがでてしまいます。構文が間違っているのでしょうか?

【test.aspx】
<html>
<head>
<title>日付テスト</title>
<script language="javascript" type="text/javascript">
function calendarPicker(strField)
{
window.open('DatePicker.aspx?field=' + strField, 'calendarPopup', 'width=250,height=220,resizable=yes');
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionStrings %>">
</asp:SqlDataSource>

<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">

<ItemTemplate>
日付:<asp:TextBox ID="TextBox" runat="server" style="text-align: center"></asp:TextBox>
<a href="javascript:;" onclick="calendarPicker('Form1.FormView1.TextBox');">▼</a><br />
</ItemTemplate>
</asp:FormView>
</form>
</body>
</html>

【DatePicker.aspx.vb】
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender

e.Cell.Controls.Clear()

Dim Link As System.Web.UI.HtmlControls.HtmlGenericControl
Link = New System.Web.UI.HtmlControls.HtmlGenericControl
Link.TagName = "a"
Link.InnerText = e.Day.DayNumberText
Link.Attributes.Add("href", String.Format("JavaScript:window.opener.document.{0}.value = '{1:d}'; window.close();", Request.QueryString("field"), e.Day.Date))

If e.Day.IsSelected Then
Link.Attributes.Add("style",Me.Calendar1.SelectedDayStyle.ToString())
End If

e.Cell.Controls.Add(Link)
End Sub

「FormView から別画面でカレンダー」の質問画像

A 回答 (1件)

エラーを見る限り、サーバーコントロール(TextBoxというIDのTextBoxコントロール)のUniqueID か ClientIDのどちらかを指定してJavaScriptを起動してあげれば、JavaScript側のエラーはなくなり、値が渡せそうな感じですけどね。


(恐らくこの例だと、UniqueID を指定してあげた方がよさそう)

VBで開発しているみたいなので、下記でいけるかなと思います。

修正前:
<a href="javascript:;" onclick="calendarPicker('Form1.FormView1.TextBox');">▼</a><br />

修正後:
<a href="javascript:;" onclick="calendarPicker('<%= Me.FormView1.Row.FindControl("TextBox").UniqueID %>');">▼</a><br />

動作の裏付けしていませんので正直回答が的を外してしまっているかもしれませんが、また別のエラーが発生するようであればご相談下さい。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!