Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

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

$
0
0

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.



Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>