473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Form.DefaultButton stopped working in firefox

hi,
asp.net 2. can anyone explain why this code does not work in firefox
(2.0.0.1), but does work in IE 7.
if you hit enter after typing something into the textbox, it should fire the
Submit button click handler, instead it fires the event for the bogus button
above it. btw it doesn't matter if i set it to ClientID, UniqueID or
"btnSubmit" hard-coded, they all fail.

<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Bogus" />
<asp:Panel ID="pnlSelect" runat="server">
<asp:TextBox ID="txtID" runat="server"
Columns="4"></asp:TextBox>
<asp:Button ID="btnSelect" runat="server"
OnClick="btnSelect_Click" Text="Submit" />
</asp:Panel>
</form>
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
Page.Form.DefaultFocus = this.txtID.ClientID;
Page.Form.DefaultButton = this.btnSelect.UniqueID;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("BOGUS BUTTON");
}

protected void btnSelect_Click(object sender, EventArgs e)
{
Response.Write("SUBMIT BUTTON");
}
}

thanks
tim

Feb 16 '07 #1
4 9710
"Tim Mackey" wrote:
hi,
asp.net 2. can anyone explain why this code does not work in firefox
(2.0.0.1), but does work in IE 7.
if you hit enter after typing something into the textbox, it should fire the
Submit button click handler, instead it fires the event for the bogus button
above it. btw it doesn't matter if i set it to ClientID, UniqueID or
"btnSubmit" hard-coded, they all fail.
<snip>

Tim,

There are a couple of things going on. First, a form tag does not have
viewstate so if you want to set the DefaultButton/DefaultFocus in the
Page_Load event, you have to do it whether or not the page is posted back.

The other thing is that controls have 3 Id properties (ClientID - for client
side javascripts, UniqueID - used internally by the postback, and ID - Id of
the control as is in the designer). From your code sample, you would need to
use the ID property.

Try this code below.

protected void Page_Load(object sender, EventArgs e)
{
this.Page.Form.DefaultButton = btnSelect.ID;
this.Page.Form.DefaultFocus = txtID.ID;
// Could also use control.Focus().
//txtID.Focus();
}

If you view the Html page source in IE and Firefox you'll see that the
defaults are rendered properly both on the first page load and after a
postback. Something like:
....
<form name="form1" method="post" action="DefaultButton.aspx"
onkeypress="javascript:return WebForm_FireDefaultButton(event, 'btnSelect')"
id="form1">
....

When you execute the above code only on the initial page load (.. if
(!IsPostBack) {...}..) then you'll notice that the defaults are correctly
rendered on the html's form tag the first time the page is loaded. Then
after the first postback they are not there.

... after postback in the html page source for both ie and firefox ..
<form name="form1" method="post" action="DefaultButton.aspx" id="form1">
...

Personally, unless I need to control the defaults programmatically, I
usually just code the defaults in the page aspx like this:

<form id="form1" runat="server" defaultbutton="btnSelect"
defaultfocus="txtID">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" ....
</form>

OR (DefaultButton on pnlSelect in case you have multiple panels on your page
or are using master page).

<form id="form1" runat="server" defaultfocus="txtID">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Bogus" />
<asp:Panel ID="pnlSelect" runat="server" DefaultButton="btnSelect">
<asp:TextBox ID="txtID" runat="server" Columns="4"></asp:TextBox>
<asp:Button ID="btnSelect" runat="server"
OnClick="btnSelect_Click" Text="Submit" />
</asp:Panel>
</form>

Hope this helps,
Jason Vermillion
Feb 17 '07 #2
Thanks for Jason's informative input.

Hi Tim,

As Jason has suggested, for the Form.DefaultButton and Form.DefaultFocus
setting code, there are two places you need change:

1. You need to put the code that configure the HtmlForm.DefaultFocus and
DefaultButton in every reques(no only the initial request)

2. You should use "ID" property rather than "ClientID" or "uniqueID".
Actually, for server-side processing, generally we only need to use
Control's ID(the other twos are mostly used for client-side processing).

Here is the modified codebehind code snippet I've used correctly on my
side(win XP sp2, ie7 and ff2.0):

=====================

public partial class nav_NavButtonPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

Page.Form.DefaultButton = btnSelect.ID;
Page.Form.DefaultFocus = txtID.ID;
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("BOGUS BUTTON");

}
protected void btnSelect_Click(object sender, EventArgs e)
{
Response.Write("SUBMIT BUTTON");
}
}

===========================

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 19 '07 #3
hi guys,
many thanks for the detailed replies.
i was a bit thrown because i read in the HtmlForm.DefaultButton property in
the docs that "If you are using master pages in your application and you are
setting the DefaultButton property from a content page, use the UniqueID
property of the IButtonControl button", and assumed this would also work for
normal pages. i re-read it now and it does clearly say to use the ID
property first, so my bad, but it is slightly annoying that the behaviour
changes for master pages or normal pages, particularly because we can't use
the declarative syntax for child pages since the form tag is in the master
page.

thanks anyway, i can live with it!
tim

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:K$*************@TK2MSFTNGHUB02.phx.gbl...
Thanks for Jason's informative input.

Hi Tim,

As Jason has suggested, for the Form.DefaultButton and Form.DefaultFocus
setting code, there are two places you need change:

1. You need to put the code that configure the HtmlForm.DefaultFocus and
DefaultButton in every reques(no only the initial request)

2. You should use "ID" property rather than "ClientID" or "uniqueID".
Actually, for server-side processing, generally we only need to use
Control's ID(the other twos are mostly used for client-side processing).

Here is the modified codebehind code snippet I've used correctly on my
side(win XP sp2, ie7 and ff2.0):

=====================

public partial class nav_NavButtonPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

Page.Form.DefaultButton = btnSelect.ID;
Page.Form.DefaultFocus = txtID.ID;
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("BOGUS BUTTON");

}
protected void btnSelect_Click(object sender, EventArgs e)
{
Response.Write("SUBMIT BUTTON");
}
}

===========================

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.
Feb 19 '07 #4
Thanks for your reply Tim,

Yes, you're right that for master page scenario, the "DefaultButton" and
"DefaultFocus" expect a different ID schema. For "DefaultButton" it expect
you to provide the Control.UniqueID while for "DefaultFocus", it expect you
to assign the Control.ClientID. Here is another thread I've been discussing
on this:

http://groups.google.com/group/micro...rk.aspnet/brow
se_thread/thread/cd7c8c8ca73c3dac/ec126335ec8184eb

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tyler Carver | last post by:
I have found a situation where the DefaultButton and DefaultFocus stop working under FireFox. I'm looking for any kind of fix or work around. The problem seems to happen when setting a control...
0
by: Tim_Mac | last post by:
i say "bug" in quotes because i can't really blame microsoft for a feature not working in a non-microsoft browser. However, i would have preferred if they did some better browser testing! if i...
7
by: Tim_Mac | last post by:
this is a re-post of an earlier message. i'm posting it under my MSDN alias for a better chance of reply :) when you press return in a multiline textbox, you expect to insert a newline. ...
1
by: ravindradonkada | last post by:
Hi, I am Ravindra,presently doing a project in asp.net. The Login page of my Web Project consists of two Buttons. If user enters his username and password and clicks on enter button of keyboard,...
3
by: John Mott | last post by:
Hi All, I'm trying to set the defaultbutton for a form to a button contained in a step template for a wizard control. This is the code in PreRender: switch (myWizard.ActiveStep.StepType) {...
18
by: Axel Dahmen | last post by:
Hi, trying to submit an ASPX form using the key (using IE6) the page is not submitted in my web project. Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client...
9
by: Veerle | last post by:
Hi, When you use multiple asp:Buttons on one Form, then asp.net generates html submit buttons for all of them. When you put your cursor in one of the textfields of the form, the default submit...
1
by: koraykazgan | last post by:
Hi all, I have a user control (ASCX). In that user control there is a panel, and inside that panel there is a textbox and a button. The panel has a DefaultButton property set, which is set to the...
0
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I have a MasterPage but on each particular page that uses it, I need to be able to set the DefaultButton for the Form for that page. From the .cs file of my ASPX page, I have tried: -...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.