Finding a child control via Javascript

veronica86

Member
Joined
Mar 3, 2005
Messages
14
Location
Iowa
Programming Experience
3-5
hello,

What I am attempting to do, is to handle when a user presses the enter key in my .net web application. If the enter key is pressed, then I want to simulate what would happen if the "Next" link button on my web page is clicked.
I register the javascript via the Page_PreRender event. The code below works fine, IF my "Next" link button is on the web page. My problem now, is that the "Next" link button is actually on a user control, that is placed on the web page. I believe this makes it a child control. I think the problem is highlighted in red below. I don't think "btnNext" can be found, since it is embedded in my user control.
Is there a way to reference this child control? Thanks for anything!

****** THE CODE ***************************

Private Sub SetEnterKeyScript()
Dim strScript As String
'“13” is the ASCII equivalent of the Enter key
strScript = "<script language=javascript type=text/javascript>"
strScript = strScript & "document.onkeypress = handler;"
strScript = strScript & "function handler(e) {"
strScript = strScript & "e = window.event;"
strScript = strScript & "key = e.keyCode;"
strScript = strScript & "if(key == 13) { "
strScript = strScript & "__doPostBack('btnNext','');"
strScript = strScript & "}"
strScript = strScript & "}"
strScript = strScript & "</script>"
Page.RegisterStartupScript("ClientScript", strScript)
End Sub

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
'If btnNext.Visible = True Then
SetEnterKeyScript()
'End If
End Sub
**************************************************
 
here's a hint: accept a parameter to your javascript function. then send in the client id of the control as the parameter.
 
Back
Top