textbox control question

C

chenhong

I have a aspx page which has a textbox control and a button control.
I added some code in the button's OnClick event.
When I add some text in the textbox and hit ENTER,the page postback and the
button's OnClick event won't be excuted.
What do I do to make it work.

Thanks.
 
C

chenhong

here is the code.
when I click the button, I get the right result.
but when the focus is on the textbox and I hit the ENTER key, the textbox's
content won't change to "ok"


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "ok";
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" /></div>
</form>
</body>
</html>

----- Original Message -----
From: "Mark Rae [MVP]" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Saturday, July 14, 2007 6:35 PM
Subject: Re: textbox control question
 
R

Riki

chenhong said:
I have a aspx page which has a textbox control and a button control.
I added some code in the button's OnClick event.
When I add some text in the textbox and hit ENTER,the page postback
and the button's OnClick event won't be excuted.
What do I do to make it work.

Thanks.

Capture the Textbox's OnTextChanged event and add your code there.
 
A

Alexey Smirnov

here is the code.
when I click the button, I get the right result.
but when the focus is on the textbox and I hit the ENTER key, the textbox's
content won't change to "ok"

Add the following code to your page

protected void Page_Load(object sender, System.EventArgs e)
{
Page.RegisterHiddenField("__EVENTTARGET", "Button1");
}

Hope this helps.
 

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

Top