Saturday, March 24, 2012

Set Focus to control

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.

--
Thanks in advance,

sck10Hi,

Try:

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

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"sck10" <sck10@.online.nospam> wrote in message
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> 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.
> --
> Thanks in advance,
> sck10
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

"sck10" <sck10@.online.nospam> ha scritto nel messaggio
news:OLLy0hGvEHA.3728@.TK2MSFTNGP12.phx.gbl...
> 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.
> --
> Thanks in advance,
> sck10

0 comments:

Post a Comment