I am working on asp.net project. I have a search textbox in it. when I search first time it work properly. Then after refresh the page textbox value is not clearing.
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { txtEmployeeID.Text = string.Empty; } txtEmployeeID.Focus(); }
If you are just refreshing by pressing F5 or Ctrl + R then it is considered as just a page refresh. There is a difference in refresh and a postback.
Please refer the below article http://www.codeproject.com/Articles/68371/Detecting-Refresh-or-Postback-in-ASP-NET
try this code in your mark up set autopostback in your textbox as true
protected void Page_Load(object sender, EventArgs e)
{
if(Page.IsPostBack)
{
txtEmployeeID.Text = string.Empty;
}
txtEmployeeID.Focus();
}
just remove "!" in your if statement, or remove the if statement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.