从下拉列表中选择一个项目后,我需要将焦点放在文本框上。
我尝试过control.focus()和setfocus()。
我尝试的最后一件事是Set_Focus(dtbEffectiveDate.ClientID),它在SelectedIndexChanged方法中使用了folowing方法。
Protected Sub Set_Focus(ByVal ControlName As String)
Dim strScript As String
strScript = "<script language=javascript> window.setTimeout(""" + ControlName + ".focus();"",0); </script>"
RegisterStartupScript("focus", strScript)
End Sub我已经无计可施了,所以任何帮助都是很棒的。
发布于 2011-03-08 00:13:12
您应该使用document.getElementById()在javascript中选择控件
document.getElementById('"+ControlName+"').focus();类似于:
Protected Sub Set_Focus(ByVal ControlName As String)
Dim strScript As String
strScript = "<script language=javascript> window.setTimeout(document.getElementById('" + ControlName + "').focus();"",0); </script>"
RegisterStartupScript("focus", strScript)
End Sub编辑:我不能完全确定正确的VB语法来转义ControlName周围的引号。
https://stackoverflow.com/questions/5221935
复制相似问题