How to set focus to specific textboxes under different conditions in C#.net webforms?

I have four textboxes grouped to two:

  • txtbox_date_start
  • txtbox_date_end
  • txtbox_value_start
  • txtbox_value_end

enter image description here

All these four textboxes have AutoPostBack = true.

if (Page.IsPostBack)
{
    //copy value of txtbox_date_start to txtbox_date_end
    if ((txtbox_date_start.Text != "") && (txtbox_date_end.Text == ""))
    {
        txtbox_date_end.Text = txtbox_date_start.Text;

        // How?
        // if txtbox_date_start was focused, then set focus to txtbox_date_end
    }

    //copy value of txtbox_value_start to txtbox_value_end
    if ((txtbox_value_start.Text != "") && (txtbox_value_end.Text == ""))
    {
        txtbox_value_end.Text = txtbox_value_start.Text;

        // How?
        //if txtbox_value_start was focused, then set focus to txtbox_value_end
    }
}

My original pseucode is like this:

if txtbox_date_start is not empty and is focused,

--> then when press tab,

----> txtbox_date_end will be = to txtbox_date_start

------> and txtbox_date_end will be focused

same purpose for txtbox_value_start & txtbox_value_end.

I also tried to use

if ( txtbox_date_start.Focused == true)

but the Focuse() cannot be used in the if statement.


  • Edited by dchencm 16 hours 29 minutes ago
August 23rd, 2014 2:03pm

Hi,

How can a textbox be in focus if the page was re-load (Page.IsPostBack) unless you put it in focus using JS for example.

>> This question have nothing to do with forum. This is SQL Server forum and your question is regarding "asp.net Webform". I will move this thread to another forum which is more fit for this issue.

Free Windows Admin Tool Kit Click here and download it now
August 23rd, 2014 4:45pm

I dont find any asp.net Webform or MVC forum (no asp.net forum in the list).

If you want please inform us and we can move this thread to C#

August 23rd, 2014 4:49pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics