problem for chrome setfocus textbox
ScriptManager scrmgr = (ScriptManager)this.Master.FindControl("scrmgr"); scrmgr.SetFocus(txtSearch);
t开发者_StackOverflow中文版his is my coding ,it works all browser.but my problem is chrome display with selection if textbox has any value..
i want just remove the selection.......
I think there is no better solution than code your own setFocus function. The simpliest cross-browser method to remove the selection is to store the text temporarily, clear the value and set it again afterwards. Then call the js-function focus on the input-control. I think this VB.Net Code helps to get the idea(I dont know if you prefer c#):
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
setFocusOnControl(Me.TextBox1)
End Sub
Public Sub setFocusOnControl(ByVal ctrl As Control)
Dim script As String = "" & vbCrLf & _
"var control = document.getElementById('" & ctrl.ClientID & "');" & vbCrLf & _
"var temptext = control.value;" & vbCrLf & _
"control.value='';" & vbCrLf & _
"control.value=temptext;" & vbCrLf & _
"control.focus();" & vbCrLf & _
"" & vbCrLf
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "setFocusOnControlScript", script, True)
End Sub
精彩评论