Click to See Complete Forum and Search --> : Default Button - ASP.NET (Elementary ?)
Al Mowbray
05-02-2002, 10:50 PM
I would like to set a button as the default button (hitting 'Enter' is the
same as clicking the button), but don't see a property for this, yet many
web apps have this functionality. How does one go about doing this?
Thanks.
Constance J. Petersen
05-06-2002, 03:31 PM
Hi Al,
"Al Mowbray" <amowbray@charter.net> wrote in message
news:3cd1ecd6$1@10.1.10.29...
> I would like to set a button as the default button (hitting 'Enter' is the
> same as clicking the button), but don't see a property for this, yet many
> web apps have this functionality. How does one go about doing this?
Put the following code into your Page_Load event:
Page.RegisterHiddenField("__EVENTTARGET", "Button1")
changing "Button1" to the name of your default button.
Note: This relies on the following client-side script that VS .NET puts in the
code behind page:
<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform = document.Form1;
theform.__EVENTTARGET.value = eventTarget;
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
</script>
So this solution works only if the visitor’s browser supports and has enabled
client-side scripting.
--
Constance Petersen, DevX newsgroup section leader
SoftMedia Artisans, Inc.
http://www.smartisans.com
For useful, usable software and Web sites
Featured Web design: http://www.keweenawnow.com/
--
Please reply in the newsgroup so everyone can benefit
Al Mowbray
05-07-2002, 01:59 PM
Works perfectly!! Many thanks.
Al Mowbray
"Constance J. Petersen" <constance@smartisans.com> wrote:
>Hi Al,
>
>"Al Mowbray" <amowbray@charter.net> wrote in message
>news:3cd1ecd6$1@10.1.10.29...
>> I would like to set a button as the default button (hitting 'Enter' is
the
>> same as clicking the button), but don't see a property for this, yet many
>> web apps have this functionality. How does one go about doing this?
>
>Put the following code into your Page_Load event:
>
> Page.RegisterHiddenField("__EVENTTARGET", "Button1")
>
>changing "Button1" to the name of your default button.
>
>Note: This relies on the following client-side script that VS .NET puts
in the
>code behind page:
>
> <script language="javascript">
> <!--
> function __doPostBack(eventTarget, eventArgument) {
> var theform = document.Form1;
> theform.__EVENTTARGET.value = eventTarget;
> theform.__EVENTARGUMENT.value = eventArgument;
> theform.submit();
> }
> // -->
> </script>
>
>
>So this solution works only if the visitor’s browser supports and has enabled
>client-side scripting.
>
>--
>Constance Petersen, DevX newsgroup section leader
>SoftMedia Artisans, Inc.
>http://www.smartisans.com
>For useful, usable software and Web sites
>Featured Web design: http://www.keweenawnow.com/
>--
>Please reply in the newsgroup so everyone can benefit
>
>
>
Johan R
05-07-2002, 06:20 PM
Hi,
I tried this as well but it doesn't seem to work for me. I have a calendar,
2 textbox and 3 button controls (webcontrols) on my page.
The script is generated in the HTML, the __EVENTTARGET is properly set in
the HTML but the ENTER stroke still invokes the first button painted.
Did I miss something ?
Johan.
devx.com
Copyright Internet.com Inc. All Rights Reserved