textBox focus

  • Thread starter Thread starter Hrvoje Voda
  • Start date Start date
hello ,
if it is a windows form the textbox has a focus metod .
If it is a web form
write client script block

below is an example

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
Inherits="ClientSideScriptExample.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function cmdButton1_Clicked()
{ document.all('txtInput1').focus();
return false;
}

function cmdButton2_Clicked()
{ document.all('txtInput2').focus();
return false;
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
InputBox 1:
<asp:TextBox ID="txtInput1" Runat="server" Width="50" />
<br>
InputBox 2:
<asp:TextBox ID="txtInput2" Runat="server" Width="50" />
<br>
<br>
Click a button to set focus on the specified control:<br>
<input ID="cmdButton1" type="button" value="InputBox 1"
OnClick="return cmdButton1_Clicked()">
<input ID="cmdButton2" type="button" value="InputBox 2"
OnClick="return cmdButton2_Clicked()">
</form>
</body>
</HTML>


regards
Ansil
Trivandrum
 
Hi,

For a web form you will need to write client side script. You can add
script to the onclick event of the radio button such as:

onclick="javascript: Form1.TextBox1.focus();"

and this will set the focus to TextBox1. If you are using a windows form
you can use the Control.Focus() method.

I hope this helps.
--------------------
//for clientside web form help see
http://support.microsoft.com/kb/816166/EN-US/

//for windows forms hel
http://msdn.microsoft.com/library/d...fsystemwindowsformscontrolclassfocustopic.asp
 
Back
Top