Set Focus to control

S

sck10

Hello,

I have a content page (I am using a Master Page) that has a control
"ddlRequestType".

In my code behind, I am using the following to create an image and assign
JavaScript to it that will set the focus to the control "ddlRequestType":

If Trim(Me.ddlRequestType.SelectedItem.Text) = "None Selected" Then
strValidateText &= _
"<tr>" & _
"<td width=200><div align=left>Request Type</div></td>" & _
"<td width=400><div align=left><A HREF=#
ONCLICK=ddlRequestType.focus()>" & _
"<IMG SRC=../../images/art_dbflash_go.jpg BORDER=0 ALT=GoTo>" & _
"</div></td>" & _
"</tr>"
strValidateForm = "Validation Error"
End If


However, when I click on the image, I get the following error:
ddlRequestType is undefined.

Any help with this would be appreciated.
 
K

Ken Dopierala Jr.

Hi,

Try:

document.getElementById('ddlRequestType').focus(); or
Form1.getElementById('ddlRequestType').focus();

Good luck! Ken.
 
C

Cirrosi

I suggest you to don't use direct id or name for referencing javascript
object, try this:
HREF="javascript:document.getElementById('ddlRequestType').focus()"

However i tink is better don't use string for create controls, try add
controls using TableCell,TableRow,ImageButton.
This is a simple example:

Dim tempRow as new TableRow()
Dim tempCell as new TableCell()
Dim myButton as new ImageButton
'Assign properties to rows and cell
myButton.attributes("onclick")="document.getElementById('ddlRequestType').focus()"
tempCell.Controls.Add(myButton )
tempRow.Cells.Add(tempCell)
'add your row to your table rows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top