Reputation: 41
I'm trying to position the cursor at the end of a textbox with.....
<asp:TextBox ID="TextBox1" AutoPostBack="true" EnableViewState="true"
runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
and then
TextBox1.Select(TextBox1.Text.Length, 0);
but Visual Studio says:
"Error 5 No overload for method 'Select' takes 2 arguments D:\Doc\t.aspx.cs"
How to do it?
Many thanks.
Regards.
Gius.
Upvotes: 1
Views: 1847
Reputation: 66389
You can do that only with JavaScript. Most simple way would be to focus the textbox then add empty string to its value, on page load event. Just add this code into your <head>
section:
<script type="text/javascript">
window.onload = function() {
var oInput = document.getElementById("<%=TextBox1.ClientID%>");
oInput.focus();
oInput.value += "";
};
</script>
And it will have the desired effect as far as I can tell.
Live test case.
Upvotes: 1
Reputation: 111850
You probably read of System.Windows.Controls.TextBox.Select or of System.Windows.Forms.TextBoxBase.Select.
Sadly System.Web.UI.WebControls.TextBox doesn't implement the Select
method.
Upvotes: 0