Solved

Restore focus after postback

Posted on 2015-02-07
5
123 Views
Last Modified: 2015-06-07
Hello,

I am not able to keep the focus on my textbox after the postback.
After postback, my focus goes to the URL automatically.

Here is what I have in my cs code:
  protected void Page_Load(object sender, EventArgs e)
    {
     
        Tbx_VIN.Focus();
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        Label4.Text ="VIN scanned:" +Tbx_VIN.Text;
        SqlDS_barcode.Insert();
        Tbx_VIN.Text = "";
        Tbx_VIN.Focus();
    }
    protected void GridView1_PreRender(object sender, EventArgs e)
    {
        Tbx_VIN.Focus();
    }

Thanks
0
Comment
Question by:arnololo123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40595587
 protected void Page_Load(object sender, EventArgs e)
    {
      if (IsPostBack) 
        {
           // Response.Write("IsPostBack");
           Tbx_VIN.Focus();
        }
        else
        {
           // Response.Write("Not IsPostBack");
        }
    }

Open in new window

0
 

Author Comment

by:arnololo123
ID: 40595644
Thanks but it does not work.
I forget to mention that I am using a scanner to scan a barcode.
It seems that the problem only occur if I use the  barcode scanner, if I just type something and click away, the focus will stay.

Regards
0
 
LVL 5

Expert Comment

by:Greg Gamble
ID: 40596552
If this is an HTML5 project just add the parameter 'autofocus' to the control.  It might show as an error in the IDE, but it'll be fine and will validate .
0
 

Author Comment

by:arnololo123
ID: 40673082
This is not HTML5
0
 
LVL 25

Accepted Solution

by:
apeter earned 500 total points
ID: 40676894
One the client side(javascript), you can set the focus. Maybe "document ready" or "onload" events
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

628 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