Solved

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

Posted on 2012-03-21
3
317 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 74

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now