Set focus and postback issue

R

Rey

Howdy all.
Using visual web developer (VB) on xp pro box.

My problem with with a web form that on accessing the calendar control
causes a postback that moves the cursor back to the txtFirstName
field.

Form uses the Page_LoadComplete in order to access the last employeeID
# in a dataview which is populated by an sqlDataObject querying an SQL
Server dbs.

Am using javascript to cause the cursor to move to the txtFirstName
field after updating the txtEmployeeID field. Reason is that for me no
other method would advance the cursor to the txtFirstName field.

However, after tabbing through the first, last and hire fields to
access the calendar button - using an image button but same issue
occurs with regular button - on clicking the image button to display
the calendar object, you see the cursor move to the txtFirstName
field. Then after selecting the appropriate date, the cursor moves to
the department dropdown (unbound). No further movement is noticed as
I'm just tabbing through the fields to the Submit New Employee button.
All the dropdowns are set to autopostback = false.

Would greatly appreciate your suggestions/comments on how to move the
cursor to the txtFirstName field and not have it move back to this
field on a postback.

Thank you,

Rey




Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.LoadComplete
' obtaining last employeid after page loaded since I'm using the
sqldata obj

'If Not IsPostBack Then
Dim intLastID As Integer
'Dim test As Control = FindControl("txtFirstName") ' trying
to set focus

intLastID =
Convert.ToInt32(grdLastEmployee.Rows.Item(0).Cells.Item(0).Text)

txtEmployeeID.Text = (intLastID + 1).ToString

' txtFirstName.Focus() ' does not work - results in cursor
being in front of the new employee #


'End If

End Sub

<script language="JavaScript">
function setFocus()
{
Form1.txtFirstName.focus();

}
</script>

<body leftmargin="0" topmargin="0" style="text-align: center"
onload="setFocus();" ><form id="Form1" runat="server" >
 
R

Rey

Forgot to mention that form in question is a multivew form.
Thanks,
Rey

Disregard - my error & frustration. Found that I had the focus set to
the txtEmployeeID field after the multivew form was selected. This
would then cause the cursor to move back to the field.

Thanks
 

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

Top