Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 126
  • Last Modified:

Restore focus after postback

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
arnololo123
Asked:
arnololo123
1 Solution
 
Mike EghtebasDatabase and Application DeveloperCommented:
 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
 
arnololo123Author Commented:
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
 
Greg GambleProgrammerCommented:
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
 
arnololo123Author Commented:
This is not HTML5
0
 
apeterCommented:
One the client side(javascript), you can set the focus. Maybe "document ready" or "onload" events
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now