Solved

Restore focus after postback

Posted on 2015-02-07
5
113 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
5 Comments
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
 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
Comment Utility
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:bmxer
Comment Utility
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
Comment Utility
This is not HTML5
0
 
LVL 25

Accepted Solution

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

11 Experts available now in Live!

Get 1:1 Help Now