473,773 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DefaultButton of html form

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 form. But
sometimes, you want the default button to be the second or third
submit button of your form. No problem, you can set this by using the
DefaultButton property of the Form. Asp.net then generates an
attribute for the html form so that a javascript method makes sure
that the other submit button is used as default button (for when
someone presses enter). This generated attribute looks something like
this: onkeypress="jav ascript:return WebForm_FireDef aultButton(even t,
'...')"

So far so good, only, Internet Explorer does not know we are altering
the default submit button to another submit button than the first one,
because this is done through javascript. So visually, it still draws
some kind of border round the first submit button, thinking this is
the default submit button. My question now is, how can I change this
behaviour so that Internet Explorer draws this extra border around the
real default button (set by javascript)?

Css doesn't seem to be much of a help, as IE6 doesn't support
"outline", ":focus", ":active" or any other stuff that you could use
to try and make things differently. So I guess that if there is a
solution, it should be something in javascript?

Any ideas?
Veerle

Mar 26 '07 #1
9 6771
On Mar 26, 9:30 am, "Veerle" <veerleve...@ho tmail.comwrote:
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 form. But
sometimes, you want the default button to be the second or third
submit button of your form. No problem, you can set this by using the
DefaultButton property of the Form. Asp.net then generates an
attribute for the html form so that a javascript method makes sure
that the other submit button is used as default button (for when
someone presses enter). This generated attribute looks something like
this: onkeypress="jav ascript:return WebForm_FireDef aultButton(even t,
'...')"

So far so good, only, Internet Explorer does not know we are altering
the default submit button to another submit button than the first one,
because this is done through javascript. So visually, it still draws
some kind of border round the first submit button, thinking this is
the default submit button. My question now is, how can I change this
behaviour so that Internet Explorer draws this extra border around the
real default button (set by javascript)?

Css doesn't seem to be much of a help, as IE6 doesn't support
"outline", ":focus", ":active" or any other stuff that you could use
to try and make things differently. So I guess that if there is a
solution, it should be something in javascript?

Any ideas?
Veerle
Try to RegisterHiddenF ield

Sub Page_Load(...)

Page.RegisterHi ddenField("__EV ENTTARGET", "Button2")

End Sub

Mar 26 '07 #2
Try to RegisterHiddenF ield
>
Sub Page_Load(...)

Page.RegisterHi ddenField("__EV ENTTARGET", "Button2")

End Sub
Thanks 4 the suggestion...
I tried:

ourForm.Default Button = defaultButtonUn iqueID;
Page.ClientScri pt.RegisterHidd enField("__EVEN TTARGET",
defaultButtonUn iqueID);

in the prerender of the masterpage, which is where the DefaultButton
code already was. But this doesn't do much: when I look in the
generated html, I see:

<input type="hidden" name="__EVENTTA RGET" id="__EVENTTARG ET" value="" /
>
but i expected to find the uniqueid of my button in the value
attribute.

And suppose that the hidden field contained the unique id of my
overrided default button, I don't see how Internet Explorer is going
to see that this is this is the submit button he has to draw the black
outline (visuallising the default button) around...

Mar 26 '07 #3
On Mar 26, 10:17 am, "Veerle" <veerleve...@ho tmail.comwrote:
Try to RegisterHiddenF ield
Sub Page_Load(...)
Page.RegisterHi ddenField("__EV ENTTARGET", "Button2")
End Sub

Thanks 4 the suggestion...
I tried:

ourForm.Default Button = defaultButtonUn iqueID;
Page.ClientScri pt.RegisterHidd enField("__EVEN TTARGET",
defaultButtonUn iqueID);

in the prerender of the masterpage, which is where the DefaultButton
code already was. But this doesn't do much: when I look in the
generated html, I see:

<input type="hidden" name="__EVENTTA RGET" id="__EVENTTARG ET" value="" /
Well, but what the defaultButtonUn iqueID is?

I forgot that the UniqueID might help

If you have a button named "Button2"

try

Page.RegisterHi ddenField("__EV ENTTARGET", Button2.UniqueI D)

(or check the name of the button through the rendered html code)

Mar 26 '07 #4
I tried this: Page.RegisterHi ddenField("__EV ENTTARGET",
Button2.UniqueI D)
And I checked using a breakpoint that Button2.UniqueI D is correct, and
it is.
But in the generated html, the hidden field is not filled in:

<input type="hidden" name="__EVENTTA RGET" id="__EVENTTARG ET" value="" /
>


On 26 mrt, 10:29, "Alexey Smirnov" <alexey.smir... @gmail.comwrote :
On Mar 26, 10:17 am, "Veerle" <veerleve...@ho tmail.comwrote:
Try to RegisterHiddenF ield
Sub Page_Load(...)
Page.RegisterHi ddenField("__EV ENTTARGET", "Button2")
End Sub
Thanks 4 the suggestion...
I tried:
ourForm.Default Button = defaultButtonUn iqueID;
Page.ClientScri pt.RegisterHidd enField("__EVEN TTARGET",
defaultButtonUn iqueID);
in the prerender of the masterpage, which is where the DefaultButton
code already was. But this doesn't do much: when I look in the
generated html, I see:
<input type="hidden" name="__EVENTTA RGET" id="__EVENTTARG ET" value="" /

Well, but what the defaultButtonUn iqueID is?

I forgot that the UniqueID might help

If you have a button named "Button2"

try

Page.RegisterHi ddenField("__EV ENTTARGET", Button2.UniqueI D)

(or check the name of the button through the rendered html code)

Mar 26 '07 #5
On Mar 26, 10:45 am, "Veerle" <veerleve...@ho tmail.comwrote:
I tried this: Page.RegisterHi ddenField("__EV ENTTARGET",
Button2.UniqueI D)
And I checked using a breakpoint that Button2.UniqueI D is correct, and
it is.
But in the generated html, the hidden field is not filled in:

<input type="hidden" name="__EVENTTA RGET" id="__EVENTTARG ET" value="" /

On 26 mrt, 10:29, "Alexey Smirnov" <alexey.smir... @gmail.comwrote :
On Mar 26, 10:17 am, "Veerle" <veerleve...@ho tmail.comwrote:
Try to RegisterHiddenF ield
Sub Page_Load(...)
Page.RegisterHi ddenField("__EV ENTTARGET", "Button2")
End Sub
Thanks 4 the suggestion...
I tried:
ourForm.Default Button = defaultButtonUn iqueID;
Page.ClientScri pt.RegisterHidd enField("__EVEN TTARGET",
defaultButtonUn iqueID);
in the prerender of the masterpage, which is where the DefaultButton
code already was. But this doesn't do much: when I look in the
generated html, I see:
<input type="hidden" name="__EVENTTA RGET" id="__EVENTTARG ET" value="" /
Well, but what the defaultButtonUn iqueID is?
I forgot that the UniqueID might help
If you have a button named "Button2"
try
Page.RegisterHi ddenField("__EV ENTTARGET", Button2.UniqueI D)
(or check the name of the button through the rendered html code)- Hide quoted text -

- Show quoted text -
Okay, I've created a test page, placed two TextBox and two Button
Controls on it and added the following code

protected void Page_Load(objec t sender, EventArgs e)
{
//Page.ClientScri pt.RegisterHidd enField("__EVEN TTARGET",
Button2.UniqueI D);
Page.Form.Defau ltButton = Button2.UniqueI D;
}

protected void Button1_Click(o bject sender, EventArgs e)
{
Response.Write( "Button1");
}

protected void Button2_Click(o bject sender, EventArgs e)
{
Response.Write( "Button2");
}

When Enter is pressed I see "Button2" on the page.

This is about using the DefaultButton property (it seems to work)

My first suggestion to use the RegisterHiddenF ield is not working when
you have two TextBoxes on the page, it works properly with one TextBox
and two Buttons only. More about that issue you can find here
http://www.hanselman.com/blog/PermaL...f-dd62c8f92c23

Mar 26 '07 #6
On Mar 26, 11:36 am, "Alexey Smirnov" <alexey.smir... @gmail.com>
wrote:
On Mar 26, 10:45 am, "Veerle" <veerleve...@ho tmail.comwrote:
Sorry, forgot to mention

the focus seems strange, however, until you don't click on any text
field you can properly set it with the TabIndex Property

Button2.TabInde x = 0;
Button1.TabInde x = 1;

although, when TextBox is "clicked" IE changes the focus to the first
button again...

Mar 26 '07 #7
On 26 mrt, 11:36, "Alexey Smirnov" <alexey.smir... @gmail.comwrote :
More about that issue you can find here http://www.hanselman.com/blog/PermaL...2ee-331f-480a-...
This is discussion from the year 2004, from before .NET 2.0. They seem
to be discussing the issue of what happens when you press enter and
how to control that. Now that we have .NET 2.0, we can use the
DefaultButton property to do this. So I just need to get the black
border around the default button that was set with DefaultButton.

Mar 26 '07 #8
On Mar 26, 12:02 pm, "Veerle" <veerleve...@ho tmail.comwrote:
On 26 mrt, 11:36, "Alexey Smirnov" <alexey.smir... @gmail.comwrote :
More about that issue you can find herehttp://www.hanselman.c om/blog/PermaLink.aspx? guid=3f96f2ee-331f-480a-...

This is discussion from the year 2004, from before .NET 2.0. They seem
to be discussing the issue of what happens when you press enter and
how to control that. Now that we have .NET 2.0, we can use the
DefaultButton property to do this. So I just need to get the black
border around the default button that was set with DefaultButton.
I think I got it.

protected void Page_Load(objec t sender, EventArgs e)
{
Button1.UseSubm itBehavior = false;
Button2.UseSubm itBehavior = true;

Page.Form.Defau ltFocus = Button2.ClientI D;
}

Mar 26 '07 #9
This seems to work very well indeed! Thanks a lot for helping out!

I was already wondering why ASP.NET generated submit buttons instead
of regular buttons, because they manage the real postback using
javascript which can as well be done with regular buttons. But I
didn't know there was property to change this.

On 26 mrt, 12:56, "Alexey Smirnov" <alexey.smir... @gmail.comwrote :
On Mar 26, 12:02 pm, "Veerle" <veerleve...@ho tmail.comwrote:
On 26 mrt, 11:36, "Alexey Smirnov" <alexey.smir... @gmail.comwrote :
More about that issue you can find herehttp://www.hanselman.c om/blog/PermaLink.aspx? guid=3f96f2ee-331f-480a-...
This is discussion from the year 2004, from before .NET 2.0. They seem
to be discussing the issue of what happens when you press enter and
how to control that. Now that we have .NET 2.0, we can use the
DefaultButton property to do this. So I just need to get the black
border around the default button that was set with DefaultButton.

I think I got it.

protected void Page_Load(objec t sender, EventArgs e)
{
Button1.UseSubm itBehavior = false;
Button2.UseSubm itBehavior = true;

Page.Form.Defau ltFocus = Button2.ClientI D;

}

Mar 26 '07 #10

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

Similar topics

0
1198
by: Jeff | last post by:
We have 3 environments, Dev, Qa, Prod. I'm working on an application that has a search page. On the search page is 3 panels. One panel is the advanced search, another a normal search and the third contains a search and clear button. I hide one of the search panels based on what the user wants. When search is clicked a datagrid is populated to the right of the panels. What I want is for the search button to be "clicked" when the user...
0
1083
by: Evert Wiesenekker | last post by:
I have a mail page with a send button containing three validators (2 required val. and 1 expression val.). The masterpage contains 3 imagebuttons. Now when I press enter the first time the validators do their work. But when I press enter again one of the imagebuttons on the masterpage is fired. When I remove al validators everything works fine...
2
1721
by: Oz Kologlu | last post by:
Hi folks, IE and Asp.net 2.0 are doing some pretty bizzare things. Some of our users were getting pretty weary of IE redrawing and "flashing" what is essentially a pretty static page every time there is a postback (IE Version 6.0.2900.2180.xpsp_sp2,,,,; Doesn't happen under firefox - bless those folks). Anyway try this:
1
2093
by: gferreri | last post by:
Hi all, I've stumbled on an interesting problem with the way Firefox handles form submitting with the enter key. I'm putting together a page that has one form element with multiple controls with their own textbox field and submit imagebuttons. I've set up each control in an asp:Panel with their DefaultButton property set to the proper button, so when the enter key is pressed, the proper button event handler is triggered. This works...
7
2812
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 and submits the form, when using Firefox. This is a potentially serious problem and certainly a...
3
7449
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 = "FinishButton"; break;
2
12994
by: =?Utf-8?B?QmlnSm9obg==?= | last post by:
We can set the default button and focus field in ASP.Net 2.0 on the Form tag. My form tag is in the Master page, but the controls are in containers. I read through a few articles which did not work. I added a "runat=server" to make the values visible to the devel. env. I added properties to the masters codebehind: Private strDefaultFocus As String
4
9758
by: Tim Mackey | last post by:
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"...
0
1351
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 the ID of a control of type IButtonControl
0
9621
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
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
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.