Solved

How to set the focus to a field in a web form from another Web form

Posted on 2012-03-21
3
322 Views
Last Modified: 2012-03-21
Hi Everyone,

I am new to web forms.  I have created a web form that contains Event Buttons.  When I select the Person of Interest Event Button, I am re-directed to the Person of Interest data entry web form with this coding:  Response.Redirect("./IssueAdmin.aspx").  I need for the cursor to be flashing inside the PK_DriverLicenseID_vch field in the Person of Interest Web data entry form automatically.

How can I tell the computer to set the focus to the PK_DriverLicenseID_vch field in this web form without the user selecting the field?

jjc9809
0
Comment
Question by:jjc9809
3 Comments
 
LVL 38

Assisted Solution

by:PaulHews
PaulHews earned 167 total points
ID: 37747384
You can use javascript, calling .focus() on the element in a script that is run when the document is loaded...  This is pretty trivial in jquery if you are using that library.


You can also do it from server side by calling a Focus method or setting the defaultfocus for the form:

How to: Set Focus on ASP.NET Web Server Controls
http://msdn.microsoft.com/en-us/library/ms178232.aspx
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 166 total points
ID: 37747390
0
 
LVL 19

Accepted Solution

by:
NerdsOfTech earned 167 total points
ID: 37747414
You could use any supported client-side language such as javascript to focus on the field. Here I will show  the example in Javascript.

Javascript:
<script language="javascript">
function focusMain(){
 var txtMain = document.getElementById('PK_DriverLicenseID_vch');
 txtMain.focus();
}
</script>

Open in new window


HTML:
<body onload="focusMain();">

Open in new window

...
<input type="text" name="PK_DriverLicenseID_vch" id="PK_DriverLicenseID_vch">

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question