1

I want to display the text entered in a textbox on a label character by character.

I.e, if I enter a character in textbox, I need to display that character in the label. Up to the length of the textbox, this procedure has to done for the label also.

How can i achieve this?

mdb
  • 52,000
  • 11
  • 64
  • 62
Ramakrishna
  • 83
  • 2
  • 9

3 Answers3

3
<script language="javascript">
function Changed(textControl)
{
  document.getElementbyId('label').value = textControl.value ;
}
</script>

<asp:TextBox id="txtName" runat="server" onchange="javascript:Changed(this);" />
Brij
  • 6,086
  • 9
  • 41
  • 69
0

a javascript i better in that case. for a character by character basis, use onkeypress javascript event. will also work with the onchange event.

<asp:Textbox onkeypress="WriteName(this.id);" id="txtT" runat="server">
<asp:label id="Test" runat="server">

function WriteName(id)
{
document.getElementById('<% = Test.ClientID %>').value=document.getElementById('<% = txtT.ClientID %>').value;
}
DavRob60
  • 3,517
  • 7
  • 34
  • 56
  • surely it would be `runat="client"` ? – fbstj Jul 13 '10 at 13:10
  • runat="client" does not exist, you have to use standard HTML to do this behavior. And it may need to get the controls's values form the server side on post-back (submit). – DavRob60 Jul 13 '10 at 13:32
0

could also use a single line of jQuery

$("id$=myTextBox").keypress(function() { $("id$=myLabel").html( this.value ); });
Dave Thieben
  • 5,388
  • 2
  • 28
  • 38