1

I am trying to focus in textbox after text in asp.net c# but I am unable to do it

my c# code is given below, please tell me where i am wrong:-

 TextBox txtindex = (TextBox)RptTask.Items[Nextindex].FindControl("TxtDuration");
 txtindex.Focus();
4
  • What event are you doing this in? I would actually recommend applying this focus in JavaScript rather than in C#. Also, you might consider setting the defaultfocus attribute of the form itself to TxtDuration. Commented Feb 18, 2014 at 14:21
  • Take a look at the ASP.NET Page Life Cycle Overview. Make sure nothing is happening in any events after the event handling that might change the focus after your post back. Commented Feb 18, 2014 at 14:21
  • After TextDurationChanged event i am getting it coz i am trying after postback the page Commented Feb 18, 2014 at 14:24
  • Can anybody can solve this problem,please provide me solution for it! Commented Feb 18, 2014 at 14:39

1 Answer 1

1

Apply Focus Method on Text in Page_PreRender

//pre-render code as given below, 
protected void Page_PreRender(object sender, EventArgs e)
{
   try
     {
       TextBox txtindex = (TextBox)RptTask.Items[Nextindex].FindControl("TxtDuration");
       txtindex.Focus();
     }
   catch(Exception ee)
    {
    }
} 

Hope It will Help!

Sign up to request clarification or add additional context in comments.

1 Comment

after prerender my page firing calendar prerender and dayrender events ,is this an issue of not focusing after text????

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.