473,534 Members | 2,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9727
"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
1824
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
2791
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
1347
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
7435
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
5774
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
6752
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
1340
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
7677
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7634
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5821
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
5209
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
3341
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1747
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
910
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
570
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.