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

WebForm Enter Key

I am sure this has been asked before but I cannot find it...

I would like to assign the Enter Key to one of the buttons on my web form. I cannot see a property or anything in the SDK.
Nov 18 '05 #1
6 1458
Hi Dirk,

I take it you're looking to set a default button. You can do that with

Page.RegisterHiddenField _
("__EVENTTARGET", "Button1")

You need to provide the name of the button (Button1) in this example. Sample
code below.

Does this help?

Ken
Microsoft MVP [ASP.NET]
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Page.RegisterHiddenField _
("__EVENTTARGET", "Button1")
End Sub
Private Sub Button2_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button2.Click
Label1.Text = "You clicked Cancel"
End Sub
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Label1.Text = "You clicked OK"
Label2.Text = TextBox1.Text
End Sub

<form id="Form1" method="post" runat="server">
<P>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox></P>
<P>&nbsp;
<asp:Button id="Button2" runat="server"
Text="Cancel"></asp:Button>&nbsp;
<asp:Button id="Button1" runat="server" Text="OK"></asp:Button></P>
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
<P>
<asp:Label id="Label2" runat="server"></asp:Label></P>
</form>
"Dirk" <an*******@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
I am sure this has been asked before but I cannot find it....

I would like to assign the Enter Key to one of the buttons on my web form.
I cannot see a property or anything in the SDK.


Nov 18 '05 #2
CMA
if u can use a "submit" button, u can fix this easily. it is the same way
with the old fashion.

hope this helps,
CMA
"Dirk" <an*******@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
I am sure this has been asked before but I cannot find it....

I would like to assign the Enter Key to one of the buttons on my web form.

I cannot see a property or anything in the SDK.
Nov 18 '05 #3
Thanks Ken, that is what I want to do. However it does not work, the enter key still does nothing. The only difference is that I am using c#. See below:

<body><form id="Form1" method="post" runat="server"><asp:Button id="Button1" runat="server" Text="Button1"></asp:Button><asp:Button id="Button2" runat="server" Text="Button2"></asp:Button><asp:Label id="Label1" runat="server">Label</asp:Label></form></body>

public class EnterKey : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Page.RegisterHiddenField("__EVENTTARGET", "Button1");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = "You pressed button one";
}

private void Button2_Click(object sender, System.EventArgs e)
{
Label1.Text = "You pressed button two";
}
}
Nov 18 '05 #4
Check out this article,
http://www.allasp.net/enterkey.aspx

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"Dirk" <an*******@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
I am sure this has been asked before but I cannot find it....

I would like to assign the Enter Key to one of the buttons on my web form.

I cannot see a property or anything in the SDK.
Nov 18 '05 #5
Dan
This might help:

http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

"Dirk" <an*******@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
I am sure this has been asked before but I cannot find it....

I would like to assign the Enter Key to one of the buttons on my web form.

I cannot see a property or anything in the SDK.
Nov 18 '05 #6
http://www.allasp.net/enterkey.aspx

"Dirk" <an*******@discussions.microsoft.com> wrote in message
news:FA**********************************@microsof t.com...
Thanks Ken, that is what I want to do. However it does not work, the
enter key still does nothing. The only difference is that I am using c#.
See below:

<body><form id="Form1" method="post" runat="server"><asp:Button
id="Button1" runat="server" Text="Button1"></asp:Button><asp:Button
id="Button2" runat="server" Text="Button2"></asp:Button><asp:Label
id="Label1" runat="server">Label</asp:Label></form></body>

public class EnterKey : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Page.RegisterHiddenField("__EVENTTARGET", "Button1");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = "You pressed button one";
}

private void Button2_Click(object sender, System.EventArgs e)
{
Label1.Text = "You pressed button two";
}
}


Nov 18 '05 #7

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

Similar topics

3
by: Kris | last post by:
Dear all, I know this question has been discussed in another topic but I feel that I lack a little bit of knowledge to grasp what was said there. My problem is as follows : As a trainer in a...
0
by: Scott | last post by:
I have a webform that I would like to use the autocomplete feature for all my textboxes. My textboxes are the <ASP:Textbox /> control. The only way I seem to be able to get autocomplete to work...
3
by: trint | last post by:
Ok, I have tried to do this with the System.Web.UI and can't find anything for the webform. It seems much easier for a Winform. Any help in trapping Webform keydown event and keyup event is...
1
by: bill | last post by:
There are two buttons and a textbox in a webform page. I want to store the text in textbox to the database when the user type 'enter' in the textbox. How to make the button2_click event fired when...
4
by: mg | last post by:
Is there any example code that illustrate the DataGrid insert operation? I want to insert a new row into a DataGrid (WebForm/C#). I'd like to press a button, enter the new column values in some...
4
by: Mark | last post by:
Hello All I'm trying to have a .Net app open up a web form, enter values into a text field (given the ID or Name), and submit. Ideally I could program something like 1 - Request Page given UR 2 -...
5
by: Miguel Ramirez | last post by:
Hello All, How can I call a WebForm from another WebForm when user clicks a button? Any help will be appreciate, Regards, Miguel.
3
by: No one | last post by:
Is there a way to control which button in a webform is the default for when a user hits the enter key? I need it to not be the first button, which is what seems to happen now. Thanks.
2
by: syncwa | last post by:
Hi, Can someone point me to a example on how to do this from asp.net? An example is the best. Thanks
3
by: quark1 | last post by:
How do I set the value of ProdQuality_1_hid and change the drop down list on the screeen? I tried sending to the address bar: javascript:setProdQuality_1_hid('Medium') {enter} but I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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...
0
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...
0
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,...
0
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...

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.