■25009 / inTopicNo.6) |
Re[5]: TextChangedイベントとjavascript |
□投稿者/ H.K.R. (7回)-(2008/09/13(Sat) 20:12:03)
|
以下のコードで試してみてはいかがでしょうか?
# もし外れていたらすみません。m(_ _)m
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>無題のページ</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<br /><br /><br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br /><br /><br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TbxResult" runat="server"></asp:TextBox>
</form>
</body>
</html>
Partial Class _Default
Inherits System.Web.UI.Page
Implements IPostBackEventHandler
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
Dim script1 As String = "<script type='text/javascript'>" _
+ "function MoveFocus(prev, next) {if (window.event.keyCode == 40 || window.event.keyCode == 13)" _
+ " {document.getElementById(next).focus();} else if (window.event.keyCode == 38)" _
+ " {document.getElementById(prev).focus();}}</script>"
Me.Page.ClientScript.RegisterClientScriptBlock(GetType(String), "script1", script1)
Me.AppendClientScript(TextBox1, TextBox1, TextBox2)
Me.AppendClientScript(TextBox2, TextBox1, TextBox3)
Me.AppendClientScript(TextBox3, TextBox2, TextBox3)
TextBox1.Attributes.Add("onchange", Me.Page.ClientScript.GetPostBackEventReference(Me, "TextBox1がPostBack!!"))
TextBox2.Attributes.Add("onchange", Me.Page.ClientScript.GetPostBackEventReference(Me, "TextBox2がPostBack!!"))
TextBox3.Attributes.Add("onchange", Me.Page.ClientScript.GetPostBackEventReference(Me, "TextBox3がPostBack!!"))
MyBase.OnLoad(e)
End Sub
Private Sub AppendClientScript(ByVal this As TextBox, ByVal prev As TextBox, ByVal _next As TextBox)
this.Attributes.Add("onkeydown", "MoveFocus('" + prev.ClientID + "','" + _next.ClientID + "')")
End Sub
Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
Dim tbx As TextBox = DirectCast(sender, TextBox)
TbxResult.Text = tbx.Text + "に変更!!"
End Sub
Public Sub RaisePostBackEvent1(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
Label1.Text = eventArgument
End Sub
End Class
|
|