469,602 Members | 1,818 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

key press event on a ASP.net text box

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

May 16 '06 #1
1 5355
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>

May 16 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by csgraham74 | last post: by
3 posts views Thread by jimmy | last post: by
2 posts views Thread by Greoasy | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.