Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set focus on user control textbox in aspx page?

How can I set focus on asp:TextBox which is placed inside a user control by using jquery/JavaScript function in aspx page?

like image 604
Sid M Avatar asked Aug 19 '13 09:08

Sid M


2 Answers

You can use id selector and use focus() method. For using jQuery you need to include jQuery and ensure your element is available in DOM before you access it. You can use document.ready for that.

$('#txt1').focus();

Or using plain JavaScript, focus()

document.getElementById('txt1').focus();

If you do not have ClientIDMode = static then you will need to use ClientID

$('#<%= txt1.Client %>').focus();
like image 152
Adil Avatar answered Nov 12 '22 21:11

Adil


You can try with jQuery :

$('#txt').focus();
like image 25
Pouki Avatar answered Nov 12 '22 19:11

Pouki