M
Michael Ahrens
Hi All
I have a problem with a webform with 2 Textboxes and a Button. TextBox1 has
a text changed event with autopostback true. Textbox2 has also a text
changed event with autopostback false. When the focus is set to TextBox1 and
i hit enter i get only the pageload event. When i set the focus on TextBox2
i get the pageload event and the button clicked event.
why don't i get the button clicked event, when the focus is set to
TextBox1?? It should also fire the button clicked event, because this button
is the default button of the page...
How to solve this problem??
thanks for your help
code below
ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication2._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" defaultbutton="Button1"
defaultfocus="TextBox1">
<div>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"
ontextchanged="TextBox2_TextChanged"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
</div>
</form>
</body>
</html>
CodeBehind:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
}
}
}
I have a problem with a webform with 2 Textboxes and a Button. TextBox1 has
a text changed event with autopostback true. Textbox2 has also a text
changed event with autopostback false. When the focus is set to TextBox1 and
i hit enter i get only the pageload event. When i set the focus on TextBox2
i get the pageload event and the button clicked event.
why don't i get the button clicked event, when the focus is set to
TextBox1?? It should also fire the button clicked event, because this button
is the default button of the page...
How to solve this problem??
thanks for your help
code below
ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication2._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" defaultbutton="Button1"
defaultfocus="TextBox1">
<div>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"
ontextchanged="TextBox2_TextChanged"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
</div>
</form>
</body>
</html>
CodeBehind:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
}
}
}