Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4614688
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:44:06+00:00 2026-05-22T01:44:06+00:00

The requirement is for some calculation to happen on entering a value in the

  • 0

The requirement is for some calculation to happen on entering a value in the textbox and since calculation is same ontextchanged is linked to the same event.
When I tab out it neatly goes to next control and does a postback to Calculate.

Now after the postback and the server side is called and executed, the tab order is messed up and on tab it does not bring focus to the correct control. It always points to the URL in the browser window.

Please let me know how do i retrieve the control which should be next in focus after the postback using the tabIndex.

  <asp:TextBox ID="txtDiscount" runat="server" CssClass="NormalTextBox" TabIndex="45"
                                    MaxLength="3" OnTextChanged="btnCalculatePrice_Click" AutoPostBack="True"></asp:TextBox>


  protected void btnCalculatePrice_Click(object sender, EventArgs e)
    {....

}

I tried the below code but didnt know how to fetch the exact control

   if(sender!=null)
        {
            WebControl reqCtrl = (WebControl)sender;
            int taborder = reqCtrl.TabIndex;
            int nexttabOrder = taborder + 1;

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:44:07+00:00Added an answer on May 22, 2026 at 1:44 am

    Use below code in order to set focus to next control after post back.

    protected void Page_Load(object sender, EventArgs e)
    {
    if (Page.IsPostBack)
    {
    WebControl wcICausedPostBack = (WebControl)GetControlThatCausedPostBack(sender as Page);
    int indx = wcICausedPostBack.TabIndex;
    var ctrl = from control in wcICausedPostBack.Parent.Controls.OfType<WebControl>()
    where control.TabIndex > indx
    select control;
    ctrl.DefaultIfEmpty(wcICausedPostBack).First().Focus();
    }
    }
    protected Control GetControlThatCausedPostBack(Page page)
    {
    Control control = null;
    string ctrlname = page.Request.Params.Get("__EVENTTARGET");
    if (ctrlname != null && ctrlname != string.Empty)
    {
    control = page.FindControl(ctrlname);
    }
    else
    {
    foreach (string ctl in page.Request.Form)
    {
    Control c = page.FindControl(ctl);
    if (c is System.Web.UI.WebControls.Button || c is System.Web.UI.WebControls.ImageButton)
    {
    control = c;
    break;
    }
    }
    }
    return control;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a business requirement that some users be automatically logged out of our
I have this problem containing some inequations and requirement to minimize a value. After
I'm using NServiceBus to handle some calculation messages. I have a new requirement to
I have requirement where some times I would like to load children as well
I have the following requirement: Based on some user input, I need to generate
I have a requirement to do some imports from an Excel spread sheet and
I've been given a requirement to impliment some google tracking on an RSS feed.
My requirement is to work on some interface .h files. Right now I have
I have some webserver resources protected with Form based Authentication. The requirement is to
Wondering if I could get some advice and direction on this following requirement: Need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.