Is that a problem with ASP.NET?

Hi,

I have an aspx page with a simple TextBox and a button. After i run the page, i set focus in the text box and press Enter. The page postback and go through Page_Load function, not go through the button event. Is that a problem with asp.net?
In above case, if the text box lost focus and press Enter,the page will go through Page_Load function and the button event. If we have two text box in the page,the page will go through Page_Load function and the button event when you press Enter no matter if you set focus in the text box.
The textbox is defined like <asp:TextBox ID="myText" Runat="server">. In button event function we have some code for validating textbox value. So we need to go through the button event even though we only have one textbox.
Any idea will be very appreciated.
Zhenyan
0
zhenyan
7/23/2002 1:12:57 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

4 Replies
691 Views

Similar Articles

[PageSpeed] 42

Check CodeBehind attribute of your page - it should be vb or cs file... That attribute tells to ASP whapt page contains handlers...  If it doesn't help send a source code please.
Regards.
0
Nobody
7/23/2002 2:52:49 PM
TextBox.aspx code

<%@ Page language="c#" Codebehind="TextBox.aspx.cs" AutoEventWireup="false" Inherits="WebTest.TextBox" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>TextBox</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<P></P>
<body MS_POSITIONING="GridLayout" onload="document.forms[0].elements['myButton'].focus()">
<form id="TextBox" method="post" runat="server">
<asp:TextBox ID="myText" Runat="server" ></asp:TextBox>
<%--
<asp:TextBox ID="myText1" Runat="server"></asp:TextBox>
--%>
<br><br>
<asp:Button ID="myButton" Runat="server" Width="195px"></asp:Button>
</form>
</body>
</HTML>
TextBox.aspx.cs code
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebTest
{
/// <summary>
/// Summary description for TextBox.
/// </summary>
public class TextBox : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button myButton;
protected System.Web.UI.WebControls.TextBox myText;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
int i;
i=12;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.myButton.Click += new System.EventHandler(this.myButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void myButton_Click(object sender, System.EventArgs e)
{
//test button
if (myText.Text.Trim().Equals(""))
myText.Text = "???";
}
}
}
0
zhenyan
7/23/2002 8:44:14 PM
Zhenyan,

I've had the same issue, and I used a client side script similar to this one. I can't take credit for it, but I don't remember where I found it.
<script>
function catchEnter(){
if(event.keyCode == 13)
__doPostBack('<%=myButton.ClientID%>','');
return false;
else
return true;
}
</script>
And set your body tag up like so:
<body onkeydown="return catchEnter();">
0
scottimus
6/16/2004 2:53:44 AM
A more cross-browser Javascript solution is provided by Darrell Norton

He's also simplified it into a free server control.
Alister
0
SomeNewKid
6/16/2004 5:39:34 AM
Reply:

Similar Artilces:

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Visual Studio .NET cannot create or open the application. The likeliest problem is that required components are not installed on the local Web server. Run Visual Studio .NET setup and add the Web Deve
I installed Visual Studio .NET 2003 on Windows Vista Home Premuim, but I'm unable to select "Web Development" item from "Server Components" during the installation. I installed all the pre-requisits but I can not see Front Page Server Extention in the programs. I can see also the IIS. Appreciate if any one can guide me with the solution.   Thanks.   FPSE is not included with Vista, it's a separate download.  See www.iis.net for this. JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. Tha...

Problems with the .NET 2005 web form designer
In Visual Studio.NET 2003, building a web page was very similar to building a plain old form. In 2005, everything's changed. Every control gets shifted to the top left, I have to use panels and so on to separate things, and if I have to change something later it's an absolute nightmare. Am I really stuck with this, or is there some switch somewhere that will allow me to do things the way I'm used to?   Geoffrey Callaghan Try this.  Bring up an aspx page in design (not source) mode.  This will enable the Layout menu. Goto Layout->Position->Auto-Pos...

How To Convert c#2005.net web template to vb2005.net Forms Template
I need  Convert c#2005.net web template to vb2005.net Forms Template   There are some free c# to vb converters out there which will allow you to upload a project and convert it to vb.   The programming models for windows forms and web projects are very different there is no way to convert a web to windows forms project.   http://www.carlosag.net/Tools/CodeTranslator/Default.aspx      Silverlight-helpVb TipsSpace Coast .Net User Group Hey Ajax-y, This tool really helps all programmers. I thought I would share this wit...

non .net form issue within a .net form tag
this may be a bad question... but I am adding a shopping cart to my asp.net website and it calls for the following code for the 'buy now' buttons: <form method="POST" action=http://www.cart.net/cart.aspx/CartName><input type="hidden" name="ID" value="IDName"><input type="hidden" name="Describe" value="IDName Description"><input type="hidden" name="Price" value="100.00"><input type="hidden" name="QtyMax" value="1"><input t...

vs.net web forms wysiwyg resize row problem
I don't know if someone ever when throw this problem, but something weird is happening with the wysiwyg from web forms of .net, the problem is the following: sometimes when i'm selecting a control in the HTML mode it selects to resize the row by mistake, the resize mouse pointer appears and i click to drop the resize mode, but then i'm not allowed to go outside of the table that i resized the row even dropping the resize mode, i try to change to code mode, and it allows to go beond the table but when i get cack to HTML mode it doesm't i'm forced to restart the vs.net, this is quite anoyng...

How to call a .net web service from another .net web service?
Hi all,I have developed two asp .net web services using visual studio .net 2003.I wish to call one web service from another web service.I tried adding a web reference of the web service in another web service and was able to do so.but i m not able to access the web methods provided by the web servicecould you please suggest a way to go about itExpecting quick replyThanxCharmy try to make sure that you reference it in the web reference and call it properly this is sample  [WebMethod()] public double CalcDistance(int x1, int y1, int x2, int y2) { Calculator.Service1 calc = new...

web.config problems when upgrading from .NET 2.0 Beta to .NET 2.0 release version
We uninstalled .NET 2.0 Beta and replaced it with .NET 2.0 release version.  And it messed everything up.  All applications now give weird errors indicating the lack of web.config files, despite the fact that they already have web.config files in place.  For example, the following error occurs even though the web.config file has <customErrors="Off">: Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for securit...

Net:Net:Net::LDAP::FAQ
------_=_NextPart_001_01C6429F.D89AA417 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, Net::LDAP Net::LDAPS Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, ....) password? I don't like to write the secret password to the perl file. Best regards Barbara Wilbert ------_=_NextPart_001_01C6429F.D89AA417-- Wilbert Barbara (CI/OSI) * wrote: > Hello, > > Net::LDAP > Net::LDAPS > > Is there a possible to LDAP bind with an encrypted (SHA, SSHA, CRYPT, > ......

CR 9 for VS.NET PDF problems using web forms
Hi all. I am trying to capture patient history data then summarize the data in a one page report using Crystal Report. I would like to use Adobe Plug-in to alllow for printing the report (although printing from the browser will be acceptable). I am using the code straight off of the web site: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myExportOptions As CrystalDecisions.Shared.ExportOptions Dim myDiskFileDestination As CrystalDecisions.Shared.DiskFileDestinationOptions Dim myExportFile...

Desperate Visual Studio .NET problem with Web Forms, please help
Hi, I've posted in the past about this problem and got no response, but now I'm desperate so have to try again. In Visual Studio .NET 2003, with .NET Framework 1.1, all web form controls (in fact all controls in the toolbar) are disabled. I create a webform.aspx page, I am in design view, but when I go to the "web forms" toolbar, I cannot drag anything to the page. I solved this last time by completely wiping my drive and spending three days reinstalling and updating everything. Everything in Visual Studio worked as expected for a few days, and now yet again everything is disabled. Can s...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

Can you return .net web controls in a .net page from a web service?
I've got a problem with a project. I've got to compile an entire .net page and return it as part of a Web Service for display. The problem I have is that I need to add WebControls and functionality to the page so that not only the html content and images are displayed (which I've managed) but that textboxes, labels, buttons and datasets can be displayed also. Essentially I need to make a call from one site for a page, populate the page and return it in a state as though it resided on the same server/webspace as the calling page. Code is currently built as follows into a string: strOpenHT...

Problems while porting .Net framework 1.0 (VB.Net) application to .Net Framework 1.1
Hello,   I have a ASP.Net web application,written in VB.Net,developed on .Net Framework 1.0 .I am trying to port it on to .Net framework 1.1.   For achieving this,I follow the following steps-   1.Open the project using the .vbproj file. 2.I am prompted with the conversion message "Do you want to convert the solution and all projects to .Net framework  1.1....." 3.I click "Yes" 4.I assume that the project is now converted. 5.I build the project & try to run it. 6.I get the following error -     Server Error in '/Consert.Net' Application. ...

Error:Visual Studio .NET cannot create or open the application. The likeliest problem is that required components are not installed on the local Web server. Run Visual Studio .NET setup and add the We
Hi, I installed the IIS 5.0 after VS.Net 2003 (1.1). after that I did run the aspnet_regiis -i at the visual studio command prompt. I am able to run local web application created on my PC. But when I tried to copy an web application created at shared PC into the wwwroot folder, I get the following error while trying to open the project in VS.Net. I've created the virtual directory for the project and also set the integrated windows authentication under the directory security tab in the IIS. Please help me resolving the problem. Thank You.   Do you have FrontPage Server Ext...

Web resources about - Is that a problem with ASP.NET? - asp.net.web-forms

Problem novel - Wikipedia, the free encyclopedia
Working class, or proletarian novels are often also social problem novels . This was in many ways a reaction to rapid industrialization , and ...

2016 Subaru Outback, Legacy recalled for driveshaft problem
Filed under: Recalls , Safety , Sedan , Wagon Subaru is recalling 2016 Outback and Legacy models because the driveshaft can potentially detach ...

Multi-state plans and selection problems
Kaiser Health News has a piece on the failure of multi-state plans to be successful in the exchanges. One of the big problems is pricing. They ...

Microsoft has an emoji problem
Microsoft increasingly has an emoji problem as the company's Windows 10 operating system lacks the latest set of characters. Emoji are, essentially, ...

The junk problem is bigger than oil
Some have written off the high-yield concerns as a mere effect of crude oil's slide. But that analysis appears to be badly off base.

Social media addiction is a bigger problem than you think
Social networks are massively addictive. Most people I know check and interact on social sites constantly throughout the day. And they have no ...

Problems At Snapfish Lead To Pre-Christmas Photo Scramble, Angry Customers
... reps end chats with customers before the customer is done speaking with them? Why did the customer service rep tell me there was a problem with ...

Facebook is finally fixing its ‘real name’ problem
After some controversies and embarrassing missteps, social-media giant Facebook is trying to introduce tools to let its users go by the names ...

Poll: Americans Have 99 Problems, And Terrorism Is No. 1
The number shot up from just 3 percent to 16 percent from November to December

Culture: The observer bias problem, and why you should care
... the same type of mistakes in drawing conclusions about what we observe with Islamic fundamentalism. As I wrote here , I believe that the problem ...

Resources last updated: 12/16/2015 4:44:23 PM