-
Dec 5th, 2017, 12:46 PM
#1
Thread Starter
Hyperactive Member
Focus
Hello
If I have
Code:
<asp:TextBox ID="user_name" runat="server"></asp:TextBox>
as a form field in my aspx file, how would I declare user_name.Focus() here:
Code:
Private Sub contact_form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim user_name As String
user_name.TextBox.Focus()
End Sub
I get an error here:
Code:
user_name.TextBox.Focus()
because TextBox is not a member of String.
I would prefer to use 'Focus' here and not in the aspx.vb file
Code:
<asp:TextBox ID="user_name" runat="server"></asp:TextBox>
if that is possible.
Thanks again
-
Dec 7th, 2017, 10:21 AM
#2
Re: Focus
You can use these lines in markup (caution i'm not sure if we get the textbox like that if we have a masterpage.I remember that we need to do something else, but did not look.You can always use Jquery though).
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
function GetF() {
var f = document.getElementById('<%= TextBox1.ClientID %>')
f.focus();
}
</script>
<title></title>
</head>
<body onload="GetF()">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
If you want in the code, you can use like: user_name.focus() (do not use user_name.textbox.Focus())
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Dec 7th, 2017, 11:35 AM
#3
Thread Starter
Hyperactive Member
Re: Focus
Many thanks, sapator - the vb.net code worked.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|