key press event on a ASP.net text box

D

donald

I got a ASP.net text box called textbox1 and a label called label1.

When a key is press in a text box i want it to up date the label with
what is in the textbox.

Label1.Text = TextBox1.Text;

But on a ASP.net text box there is no on key press event like this is
on a normal html text box but if i do the event in the normal html text
box i can't use the code in the .aspx.cs file.

How can i get round this?

Thanks

Donald
 
D

donald

i work out i need to do this client side so i got the below how can i
get the javascript to use the textbox and label in my asp part?

i have the below code that i started with

<%@ Page Language="C#" %>
<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Label1.Text = "Start";
}
TextBox1.Attributes.Add("onkeyup", "rewriteLabel()");
}
</script>

<script type="text/javascript">

function rewriteLabel(){
TextBox1.Text = Label1.text;
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head >
<title >test</title>
</head>
<body>
<form id="form1" runat="server">
<br />
<asp:TextBox ID="TextBox1" runat="server" /><br />
<asp:Label ID="Label1" Runat="server" BorderWidth="1px" />
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top