Javascript in V.NET

0 views
Skip to first unread message

vbnetrookie

unread,
Jul 25, 2005, 2:19:19 PM7/25/05
to DotNetDe...@googlegroups.com
Hi all,

I found a way to place the focus on certain controls in VB.NET with the
help of Javascript. This is the first time i'm using this in my code
and it seems to do the job except it doesn't always work.

I found this link:
http://www.developer.com/net/vb/article.php/2237431

I would like to be able to show the cursor in textboxes after certain
events (button clicks, oneventchange...)
But now it only does it once, whenever I start my application the first
time. Afterwards it never happens anymore.

I placed this inmy code behind:
****************
Public Sub SetFocusControl(ByVal ControlName As String)
' character 34 = "

Dim script As String = _
"<script language=" + Chr(34) + "javascript" + Chr(34) _
+ ">" + _
" var control = document.getElementById(" + Chr(34) + _
ControlName + Chr(34) + ");" + _
" if( control != null ){control.focus();}" + _
"</script>"

Page.RegisterStartupScript("Focus", script)
End Sub
***************
And I call it from certain events in the page such as:

Private Sub ddl1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ddl1.SelectedIndexChanged

SetFocusControl(txtlsu.ClientID)

End Sub

And the first time I change items it works, but the second time it
doesn't. Same with my listbox_SelectedIndexChange..

Does anyone know y this happens(actually y it's not happening..ie....
placing the cursor in the textbox)

Do I have to add something in the html section??

Thanks guys for your help!!

JMT

Reply all
Reply to author
Forward
0 new messages