473,394 Members | 2,160 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,394 software developers and data experts.

Default Button

I recently read an article that mentioned adding code to
the onload event to "register a default button".

The behavior i am after is that when the user hits enter,
the form submits.

Does anyone know how to do this using vb & asp.net?

Thanks

Jul 19 '05 #1
5 4077
If you have a submit button on the form, when the user
hits enter, it should submit the form

Tu-Thach
-----Original Message-----
I recently read an article that mentioned adding code to
the onload event to "register a default button".

The behavior i am after is that when the user hits enter,
the form submits.

Does anyone know how to do this using vb & asp.net?

Thanks

.

Jul 19 '05 #2
OK, but say that i have a login form where the button_click event runs
code that calls a stored procedure. My form will not submit when I hit
the enter key. Should i place the code in an "on_submit " event or
something?
Here is the HTML and the code behind of the login form

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="Login.aspx.vb" Inherits="OSHA.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>OSHA Reporting Login</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<LINK href="Styles.css" type="text/css" rel="stylesheet">
</HEAD>
<body bgColor="#ffffff" MS_POSITIONING="GridLayout">
<form id="frmLogin" method="post" runat="server">
<asp:label id="lblInstructions" style="Z-INDEX: 101; LEFT: 119px;
POSITION: absolute; TOP: 34px"
runat="server" Width="550px" Height="146px" BackColor="Lavender"
BorderColor="Navy" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Arial"
ForeColor="Black"></asp:label><asp:panel id="Panel1" style="Z-INDEX:
102; LEFT: 119px; POSITION: absolute; TOP: 216px" runat="server"
Width="550px" Height="136px" BackColor="Lavender"
BorderColor="DarkBlue" BorderStyle="Solid" BorderWidth="1px"
ForeColor="Black">
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="100%"
align="center" border="0">
<TR>
<TD style="WIDTH: 169px; HEIGHT: 24px">
<asp:Label id="lblDept" runat="server"
Font-Bold="True">Department Name</asp:Label></TD>
<TD style="HEIGHT: 24px">
<asp:DropDownList id="lstDepartments" runat="server"
Font-Size="X-Small"></asp:DropDownList></TD>
</TR>
<TR>
<TD style="WIDTH: 169px">
<asp:Label id="lblPassword" runat="server"
Font-Bold="True">Password</asp:Label></TD>
<TD>
<asp:TextBox id="txtPassword" tabIndex="1" runat="server"
Width="181px" Font-Size="X-Small" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1"
runat="server" Font-Names="Arial" BackColor="Transparent"
Width="244px" Font-Size="Small" ControlToValidate="txtPassword"
ErrorMessage=" * Please enter a
password"></asp:RequiredFieldValidator></TD>
</TR>
<TR>
<TD align="center" colSpan="2"><INPUT style="WIDTH: 90px; HEIGHT:
24px" tabIndex="2" type="submit" value="Login" runat="server"
onserverclick="cmdLogin_Click"></TD>
</TR>
</TABLE>
</asp:panel><asp:label id="lblDeptID" style="Z-INDEX: 103; LEFT:
125px; POSITION: absolute; TOP: 378px"
runat="server" Width="537px" Font-Names="Arial" ForeColor="Red"
Font-Size="Small"></asp:label><asp:panel id="Panel2" style="Z-INDEX:
100; LEFT: 28px; POSITION: absolute; TOP: 15px" runat="server"
Width="713px" Height="391px" BackColor="LightSteelBlue"
BorderColor="Black" BorderStyle="Solid"
BorderWidth="1px"></asp:panel></form>
</body>
</HTML>

===========

Imports System.Web.Security
Public Class WebForm1
Inherits System.Web.UI.Page
Dim connString = ConfigurationSettings.AppSettings("connString")
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents lblInstructions As
System.Web.UI.WebControls.Label
Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
Protected WithEvents lblPassword As System.Web.UI.WebControls.Label
Protected WithEvents lblDept As System.Web.UI.WebControls.Label
Protected WithEvents txtPassword As
System.Web.UI.WebControls.TextBox
Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents lstDepartments As
System.Web.UI.WebControls.DropDownList
Protected WithEvents lblDeptID As System.Web.UI.WebControls.Label
Protected WithEvents Panel2 As System.Web.UI.WebControls.Panel

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
'set label textfor login instructions
lblInstructions.Text = "<Div align='center'><H3>Welcome to
the Cityof Stamford OSHA Recording Application.</H3></DIV><p>"
lblInstructions.Text = lblInstructions.Text &
"<BlockQuote>In order to log into this application you must:<br>"
lblInstructions.Text = lblInstructions.Text & "<UL><LI>
Select your Department name from the dropdown list.<br>"
lblInstructions.Text = lblInstructions.Text & "<LI> Enter
your department's password in the box.<br>"
lblInstructions.Text = lblInstructions.Text & "<LI> Click
the Login Button<br></UL></BlockQuote>"
Dim myConnection As SqlClient.SqlConnection
Dim myCommand As SqlClient.SqlCommand

myConnection = New SqlClient.SqlConnection(connString)
myCommand = New SqlClient.SqlCommand("Select * from
Departments Order By DeptName", myConnection)
myConnection.Open()

lstDepartments.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
lstDepartments.DataTextField = "DeptName"
lstDepartments.DataBind()

End If

'set focus to select box
Dim strBuilder As System.Text.StringBuilder = New
System.Text.StringBuilder
strBuilder.Append(" <script language='javascript'> ")
strBuilder.Append("
document.getElementById('lstDepartments').focus(); ")
strBuilder.Append(" </Script> ")

RegisterStartupScript("Focus", strBuilder.ToString)

End Sub

Public Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

'Stored Procedure - name: getDept
'Uses two input parameters

Dim oCN As SqlClient.SqlConnection
Dim oCmd As SqlClient.SqlCommand
'Response.Write(lstDepartments.SelectedValue & "<br>")
'Response.Write(txtPassword.Text & "<br>")

oCN = New SqlClient.SqlConnection(connString)
oCN.Open()

oCmd = New SqlClient.SqlCommand("getDept", oCN)
oCmd.CommandType = CommandType.StoredProcedure

oCmd.Parameters.Add(New SqlClient.SqlParameter("@deptName",
SqlDbType.VarChar, 50))
oCmd.Parameters("@deptName").Value =
lstDepartments.SelectedValue
oCmd.Parameters("@deptName").Direction =
ParameterDirection.Input

oCmd.Parameters.Add(New SqlClient.SqlParameter("@Password",
SqlDbType.VarChar, 50))
oCmd.Parameters("@Password").Value = txtPassword.Text
oCmd.Parameters("@Password").Direction =
ParameterDirection.Input

oCmd.Parameters.Add(New SqlClient.SqlParameter("@deptID",
SqlDbType.VarChar, 5))
oCmd.Parameters("@deptID").Direction = ParameterDirection.Output

oCmd.ExecuteNonQuery()

Dim vReturn As String
vReturn = oCmd.Parameters("@deptID").Value

If vReturn <> "-1" Then

FormsAuthentication.RedirectFromLoginPage(oCmd.Par ameters("@deptID").Val
ue, False)
Else
lblDeptID.Text = "Your Password was not found. Please
re-enter your information."
End If

oCN.Close()

End Sub

End Class

====================

Michael

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3
When did the problem happen, when you hit Enter key in the Text box or on
the submit button?

Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."

Jul 19 '05 #4
Luke,

The problem occurs when the textbox has focus. I have observed that a
typical behavior for users to to type in their usernams / password and
hit the Enter key. This leaves the focus on the textbox while the submit
is enacted.

I have tried capturing keystrokes from within the textbox but have not
been sucessful in doing so.

Thanks,

Michael


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #5
For example:

<INPUT id="pwd" type="password">

Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/se...s/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."

Jul 19 '05 #6

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

Similar topics

1
by: Billy Jacobs | last post by:
Is there a way to make a button on a web form the default button so that when the user hits the enter button the code for that button executes? I have a web page Login.aspx where I have only 1...
0
by: Shixx | last post by:
Hello, I have problem in my web application and my web form. I have 5-6 buttons (web controls) and when I have focus on some text box, always one button becomes default and got focus, and after I...
3
by: Marty McFly | last post by:
Hello, I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the...
5
by: Wonder | last post by:
How can I create or use the msgobx to show a message without a default button. The user has explicity to click on the button, so the msgbox closes it. Thanks,
10
by: cj | last post by:
Here's an easy one, I hope. How do I make button1, which I put on this form from the toolbox, the default button on the form? I thought it used to be a property in the properties window called...
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...
3
by: Anil Kumar Sharma | last post by:
Hello, I am working on C# using vs.net 2003. I have faced two interesting problems. 1. Dynamically setting Default Button: I created a form and used it in various contexts. On basis of the...
15
by: simonoficina | last post by:
Hello all! I am a vb.net beginner in Spain. When I use VB6 ,the button object has a property called "default" that can set this button like press "ENTER" key. But in the VB.net I can't find this...
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...
4
by: Whasigga | last post by:
Hi I've created a form that has 7 subforms. It is the same subform, bound to a table, just repeated. This form represents a week, and each subform is used to enter in data for each day of the...
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: 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...
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: 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
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
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
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...

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.