posts - 116,  comments - 34,  trackbacks - 0
设置服务器端控件的焦点  :
Private Sub SetFocus(ByVal controlToFocus As Control)
Dim scriptFunction As New StringBuilder
Dim scriptClientId As String
scriptClientId = controlToFocus.ClientID
scriptFunction.Append(“<script language=’javascript’>”)
scriptFunction.Append(“document.getElementById(‘” & scriptClientId & “’).focus();”)
scriptFunction.Append(“</script>”)
RegisterStartupScript(“focus”, scriptFunction.ToString())
End Sub

调用时:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If (Page.IsPostBack = False) Then
SetFocus(TextBox1)
End If
End Sub

客户端代码的使用
  1). 可以使用客户端的事件代码,但两者不能同名,服务器端代码的名是你可以控制的。对于非ASP.NET的标准控件的自定义控件必须实现IAttributeAcces-sor接口或从WebControl派生并且可用expando属性
asp:ImageButton id=“foo”
ImageUrl=“start.jpg”
onMouseOver=“rollover(this);”
onMouseOut=“rollout(this)”
rolloversrc=“myrollover.jpg”
rolloutsrc=“myrollout.jpg”
runat=“server”/>
<input type=Button onClick=“return clientHandler()”
onServerClick=“Button1_Click” … />

 2). 使用可以在Postback之前执行客户端代码,当然也可以取消这次Postback,另外也可以访问客户端该页所有的客户端控件。
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles MyBase.Load
 RegisterOnSubmitStatement(“foo”, “return confirm(‘Are you sure you want to submit the order?’);”)
End Sub
  3). 还有更复杂的我认为不实用,大家可以自己去看,主要是运用Register-StartupScript和JavaScript的技术


posted on 2006-02-21 17:19 萌芽的叶子 阅读(386) 评论(0)  编辑 收藏 引用 所属分类: asp.net
只有注册用户登录后才能发表评论。

<2005年11月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

常用链接

留言簿(3)

随笔分类(115)

随笔档案(116)

文章分类(4)

相册

收藏夹(78)

.net中文社区

.net博客

.net英文社区

AJAX

ASP.NET 2.0

ASP.NET 学习

DataBase

ERP

E杂志

Html&Css

JavaScript

Microsoft

Open Sourse

SAP

WebCasts

WebServices

XML

其他

好友Blog

好文章连接

开发工具

控件

物流

职业经理人

设计模式

读书网站

非技术

项目管理

搜索

  •  

积分与排名

  • 积分 - 57058
  • 排名 - 108

最新评论

阅读排行榜

评论排行榜