473,545 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form.DefaultBut ton 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="Button 1_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="btnSel ect_Click" Text="Submit" />
</asp:Panel>
</form>
public partial class test : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if(!IsPostBack)
{
Page.Form.Defau ltFocus = this.txtID.Clie ntID;
Page.Form.Defau ltButton = this.btnSelect. UniqueID;
}
}
protected void Button1_Click(o bject 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 9728
"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(objec t 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="Default Button.aspx"
onkeypress="jav ascript:return WebForm_FireDef aultButton(even t, '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="Default Button.aspx" id="form1">
...

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

<form id="form1" runat="server" defaultbutton=" btnSelect"
defaultfocus="t xtID">
<asp:Button ID="Button1" runat="server" OnClick="Button 1_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="t xtID">
<asp:Button ID="Button1" runat="server" OnClick="Button 1_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="btnSel ect_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.DefaultBut ton and Form.DefaultFoc us
setting code, there are two places you need change:

1. You need to put the code that configure the HtmlForm.Defaul tFocus 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_NavButtonPa ge : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{

Page.Form.Defau ltButton = btnSelect.ID;
Page.Form.Defau ltFocus = txtID.ID;
}
protected void Button1_Click(o bject 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.Defaul tButton 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.comw rote in message
news:K$******** *****@TK2MSFTNG HUB02.phx.gbl.. .
Thanks for Jason's informative input.

Hi Tim,

As Jason has suggested, for the Form.DefaultBut ton and Form.DefaultFoc us
setting code, there are two places you need change:

1. You need to put the code that configure the HtmlForm.Defaul tFocus 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_NavButtonPa ge : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{

Page.Form.Defau ltButton = btnSelect.ID;
Page.Form.Defau ltFocus = txtID.ID;
}
protected void Button1_Click(o bject 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 "DefaultBut ton" and
"DefaultFoc us" expect a different ID schema. For "DefaultBut ton" it expect
you to provide the Control.UniqueI D while for "DefaultFoc us", it expect you
to assign the Control.ClientI D. Here is another thread I've been discussing
on this:

http://groups.google.com/group/micro...rk.aspnet/brow
se_thread/thread/cd7c8c8ca73c3da c/ec126335ec8184e b

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
1825
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 that is part of another control, like a templated control. The docs say to use the UniqueID in this case. In the example below I am trying to set...
0
1610
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 press return or enter inside a multiline textbox in firefox, with Page.Form.DefaultButton set, the form is submitted. validation will usually...
7
2793
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. However, if you set the Form.DefaultButton property, whatever javascript code is employed by Asp.Net to handle this functionality intercepts the key press...
1
1350
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, the Signin button is to be submitted not the other button. So,please specify how to get focus on the specified Button Thanks in advance.
3
7437
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) { case WizardStepType.Start: this.Page.Form.DefaultButton = "StartNextButton"; break; case WizardStepType.Finish: this.Page.Form.DefaultButton =...
18
5781
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 script code being executed having a flaw: function anonymous() { if (!ValidatedTextBoxOnKeyPress(event)) { event.cancelBubble = true; if...
9
6754
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 button is the first submit button of the form. So if you press enter, then the form is submitted as if you pressed the first submit button of the...
1
3888
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 button inside it. I also have a page, and on that page there are two instances of that user control (uc1 and uc2). I additionaly have an update...
0
1342
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: - Form.DefaultButton = MyButton; - Form.DefaultButton = MyButton.ClientID; Both of these result in a runtime error: The DefaultButton of 'MainFrm' must be...
0
7478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7668
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.