473,387 Members | 1,597 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,387 software developers and data experts.

How to get default button to work?

I have a page with 2 buttons and was told I could get my choice of button to
act as the default button but add the following code to the my Page_Load:

Page.RegisterHiddenField("__EVENTTARGET", "btnSearch")

I have the following code and page:

************************************************** **
<script runat="server">
Sub Page_Load(s as Object, e as EventArgs)
if not IsPostBack then
Page.RegisterHiddenField("__EVENTTARGET", "Button2")
end if
end sub

Sub Button1_Click(s as Object, e as EventArgs)
Label1.Text = "From Button 1"
end Sub

Sub Button2_Click(s as Object, e as EventArgs)
Label1.Text = "From Button 2"
end Sub

</script>

<form runat="server">
<table width="851" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>_
<asp:Label ID="Label1" runat="server" />
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<asp:Button ID="Button1" Text="Button1" OnClick="Button1_Click"
runat="server" />&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" Text="Button2" OnClick="Button2_Click"
runat="server" />
</form>
************************************************** ************************************************** ****************************

But it doesn't do anything until I press one of the buttons with my mouse or
tab to a button.

Is there a way to get this to work?

Thanks,

Tom
Apr 18 '06 #1
4 1469
jd
Hmm, I don't see a button named "btnSearch" on this page.

Apr 18 '06 #2
Take a look at this page. It explains how to do this in .net 2.0:

http://weblogs.asp.net/skoganti/arch...20/231695.aspx

Apr 18 '06 #3
because there are no autopostback fields on your form, the server does not
process the "__EVENTTARGET" hidden field as buttons do not require the
hidden field. you need to fake the server out by calling:

Page.GetPostBackEventReference(this);
-- bruce (sqlwork.com)
"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
I have a page with 2 buttons and was told I could get my choice of button
to act as the default button but add the following code to the my
Page_Load:

Page.RegisterHiddenField("__EVENTTARGET", "btnSearch")

I have the following code and page:

************************************************** **
<script runat="server">
Sub Page_Load(s as Object, e as EventArgs)
if not IsPostBack then
Page.RegisterHiddenField("__EVENTTARGET", "Button2")
end if
end sub

Sub Button1_Click(s as Object, e as EventArgs)
Label1.Text = "From Button 1"
end Sub

Sub Button2_Click(s as Object, e as EventArgs)
Label1.Text = "From Button 2"
end Sub

</script>

<form runat="server">
<table width="851" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>_
<asp:Label ID="Label1" runat="server" />
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<asp:Button ID="Button1" Text="Button1" OnClick="Button1_Click"
runat="server" />&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" Text="Button2" OnClick="Button2_Click"
runat="server" />
</form>
************************************************** ************************************************** ****************************

But it doesn't do anything until I press one of the buttons with my mouse
or tab to a button.

Is there a way to get this to work?

Thanks,

Tom

Apr 19 '06 #4
"bruce barker (sqlwork.com)" <b_*************************@sqlwork.com> wrote
in message news:O2**************@TK2MSFTNGP02.phx.gbl...
because there are no autopostback fields on your form, the server does not
process the "__EVENTTARGET" hidden field as buttons do not require the
hidden field. you need to fake the server out by calling:

Page.GetPostBackEventReference(this);
Where would I put this?

Tom


-- bruce (sqlwork.com)
"tshad" <ts**********@ftsolutions.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
I have a page with 2 buttons and was told I could get my choice of button
to act as the default button but add the following code to the my
Page_Load:

Page.RegisterHiddenField("__EVENTTARGET", "btnSearch")

I have the following code and page:

************************************************** **
<script runat="server">
Sub Page_Load(s as Object, e as EventArgs)
if not IsPostBack then
Page.RegisterHiddenField("__EVENTTARGET", "Button2")
end if
end sub

Sub Button1_Click(s as Object, e as EventArgs)
Label1.Text = "From Button 1"
end Sub

Sub Button2_Click(s as Object, e as EventArgs)
Label1.Text = "From Button 2"
end Sub

</script>

<form runat="server">
<table width="851" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>_
<asp:Label ID="Label1" runat="server" />
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<asp:Button ID="Button1" Text="Button1" OnClick="Button1_Click"
runat="server" />&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" Text="Button2" OnClick="Button2_Click"
runat="server" />
</form>
************************************************** ************************************************** ****************************

But it doesn't do anything until I press one of the buttons with my mouse
or tab to a button.

Is there a way to get this to work?

Thanks,

Tom


Apr 19 '06 #5

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

Similar topics

2
by: makthar | last post by:
Thanks for taking the time to read this note Can anyone explain what went wrong and any ideas how to fix it I have a search page With three buttons few drop downs and a textbox. The search...
2
by: Goober | last post by:
I have the following default.aspx page that works properly. However, what I want to do is to link the graphics within it (that are hard coded now in the default web page) to our corporate...
4
by: tshad | last post by:
I have 3 objects on my page (textbox,button and linkbutton) When I put something in my textbox and hit "enter", the page gets posted, but nothing happens. I don't go to either of the functions...
3
by: Rick Brandt | last post by:
I am using some buttons to hide/show various divs and am changing the style of the button to indicate which button's view is "active". My problem is that for the non-active buttons I want the...
1
by: JJ | last post by:
I have two related problems: (a). trying to set the default button within a CreateUserWizard control ----------------------------------------------------------------- I've done this in a messy...
1
by: JJ | last post by:
What trouble I'm having setting default buttons on a page (with a master page). I got around doing it on a page basis by calling the SetWizardDefaultButton() routine from page load. Notice how...
2
by: Gregory Gadow | last post by:
I have a large website written to use ASP.Net 2.0. The master page has a "logout" button. If the child page does not have an explicitly defined default button (most do not), the page posts back...
2
by: AlecL | last post by:
Hi All, I have added a user control onto an aspx page and want to make the submit button of that user control the default button when the panel in which the user control is located is visible. ...
12
by: Doogie | last post by:
How do I make a value the default value for a combo box in ASP 3.0? What I have below does NOT work, yet I've seen it in HTML file examples before (and works if I put it in a HTML file by itself,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.