如何在web控件中添加Js方法

     在平时的开发中,经常要在web控件中应用Js方法。下面我就介绍一下用法。
(1)给button添加Js函数。
lbnDelete.Attributes( " onclick " =   " return delConfirm(); "
(2)给TextBox添加Js函数。
 txtMenuCode.Attributes( " onblur " =   " menuCodeCheck('txtMenuCode'); "
(3)给RadioButton添加Js函数。
rbtpack.Attributes( " onclick " =   " moneyCont(2); "
(4)给DropDownList添加Js函数。
 DDtkbmncd1.Attributes( " onchange " =   " LickBumenChange(1) "
(5)给DataGrid和GridView添加Js函数。
 1  Private   Sub  dgMenu_ItemDataBound( ByVal  sender  As   Object ByVal  e  As  System.Web.UI.WebControls.DataGridItemEventArgs)  Handles  dgMenu.ItemDataBound
 2           ' メソッド名
 3           Const  methodName  As   String   =   " dgMenu_ItemDataBound "
 4           Try
 5               If  e.Item.ItemType  =  ListItemType.Item  Or  _
 6                                         e.Item.ItemType  =  ListItemType.AlternatingItem  Then
 7                  selIndex  =  selIndex  +   1
 8                   ' メニュー内容を表示中の行は、選択中(反転)表示する
 9                  e.Item.Attributes.Add( " onmouseover " " tdOnOver(this); " )
10                  e.Item.Attributes.Add( " onmouseout " " tdOnOut(this); " )
11                   ' 行をクリックするとクリックした行のメニュー内容を表示する
12                  e.Item.Attributes.Add( " onclick " " setMenuCode( "   +   " ' "   +   CStr (e.Item.Cells( 1 ).Text)  +   " ', "   +  _
13                                                                 " ' "   +   CStr (selIndex)  +   " ' "   +   " ) " )
14               End   If
15           Catch  ex  As  Exception
16               ' 想定しないタイミングで発生した例外のため、ここ扱い
17               Dim  comex  As  PosComException  =   New  PosComException(methodName, POSCOM_LOG_ERROR,  "" "" "" , ex)
18               ' 共通異常処理
19              CommonErrorManage(comex)
20           End   Try
21       End Sub

以上就是常用的后台给Web控件添加JS的方法。

你可能感兴趣的:(Web)