473,626 Members | 3,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4107
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="Log in.aspx.vb" Inherits="OSHA. WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>OSHA Reporting Login</title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
<LINK href="Styles.cs s" type="text/css" rel="stylesheet ">
</HEAD>
<body bgColor="#fffff f" MS_POSITIONING= "GridLayout ">
<form id="frmLogin" method="post" runat="server">
<asp:label id="lblInstruct ions" style="Z-INDEX: 101; LEFT: 119px;
POSITION: absolute; TOP: 34px"
runat="server" Width="550px" Height="146px" BackColor="Lave nder"
BorderColor="Na vy" BorderStyle="So lid"
BorderWidth="1p x" Font-Names="Arial"
ForeColor="Blac k"></asp:label><asp: panel id="Panel1" style="Z-INDEX:
102; LEFT: 119px; POSITION: absolute; TOP: 216px" runat="server"
Width="550px" Height="136px" BackColor="Lave nder"
BorderColor="Da rkBlue" BorderStyle="So lid" BorderWidth="1p x"
ForeColor="Blac k">
<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">Dep artment Name</asp:Label></TD>
<TD style="HEIGHT: 24px">
<asp:DropDownLi st id="lstDepartme nts" runat="server"
Font-Size="X-Small"></asp:DropDownLis t></TD>
</TR>
<TR>
<TD style="WIDTH: 169px">
<asp:Label id="lblPassword " runat="server"
Font-Bold="True">Pas sword</asp:Label></TD>
<TD>
<asp:TextBox id="txtPassword " tabIndex="1" runat="server"
Width="181px" Font-Size="X-Small" TextMode="Passw ord"></asp:TextBox>
<asp:RequiredFi eldValidator id="RequiredFie ldValidator1"
runat="server" Font-Names="Arial" BackColor="Tran sparent"
Width="244px" Font-Size="Small" ControlToValida te="txtPassword "
ErrorMessage=" * Please enter a
password"></asp:RequiredFie ldValidator></TD>
</TR>
<TR>
<TD align="center" colSpan="2"><IN PUT 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="Ligh tSteelBlue"
BorderColor="Bl ack" BorderStyle="So lid"
BorderWidth="1p x"></asp:panel></form>
</body>
</HTML>

===========

Imports System.Web.Secu rity
Public Class WebForm1
Inherits System.Web.UI.P age
Dim connString = ConfigurationSe ttings.AppSetti ngs("connString ")
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents lblInstructions As
System.Web.UI.W ebControls.Labe l
Protected WithEvents Panel1 As System.Web.UI.W ebControls.Pane l
Protected WithEvents lblPassword As System.Web.UI.W ebControls.Labe l
Protected WithEvents lblDept As System.Web.UI.W ebControls.Labe l
Protected WithEvents txtPassword As
System.Web.UI.W ebControls.Text Box
Protected WithEvents RequiredFieldVa lidator1 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents lstDepartments As
System.Web.UI.W ebControls.Drop DownList
Protected WithEvents lblDeptID As System.Web.UI.W ebControls.Labe l
Protected WithEvents Panel2 As System.Web.UI.W ebControls.Pane l

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

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

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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 &
"<BlockQuot e>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.SqlCo nnection
Dim myCommand As SqlClient.SqlCo mmand

myConnection = New SqlClient.SqlCo nnection(connSt ring)
myCommand = New SqlClient.SqlCo mmand("Select * from
Departments Order By DeptName", myConnection)
myConnection.Op en()

lstDepartments. DataSource =
myCommand.Execu teReader(Comman dBehavior.Close Connection)
lstDepartments. DataTextField = "DeptName"
lstDepartments. DataBind()

End If

'set focus to select box
Dim strBuilder As System.Text.Str ingBuilder = New
System.Text.Str ingBuilder
strBuilder.Appe nd(" <script language='javas cript'> ")
strBuilder.Appe nd("
document.getEle mentById('lstDe partments').foc us(); ")
strBuilder.Appe nd(" </Script> ")

RegisterStartup Script("Focus", strBuilder.ToSt ring)

End Sub

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

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

Dim oCN As SqlClient.SqlCo nnection
Dim oCmd As SqlClient.SqlCo mmand
'Response.Write (lstDepartments .SelectedValue & "<br>")
'Response.Write (txtPassword.Te xt & "<br>")

oCN = New SqlClient.SqlCo nnection(connSt ring)
oCN.Open()

oCmd = New SqlClient.SqlCo mmand("getDept" , oCN)
oCmd.CommandTyp e = CommandType.Sto redProcedure

oCmd.Parameters .Add(New SqlClient.SqlPa rameter("@deptN ame",
SqlDbType.VarCh ar, 50))
oCmd.Parameters ("@deptName").V alue =
lstDepartments. SelectedValue
oCmd.Parameters ("@deptName").D irection =
ParameterDirect ion.Input

oCmd.Parameters .Add(New SqlClient.SqlPa rameter("@Passw ord",
SqlDbType.VarCh ar, 50))
oCmd.Parameters ("@Password").V alue = txtPassword.Tex t
oCmd.Parameters ("@Password").D irection =
ParameterDirect ion.Input

oCmd.Parameters .Add(New SqlClient.SqlPa rameter("@deptI D",
SqlDbType.VarCh ar, 5))
oCmd.Parameters ("@deptID").Dir ection = ParameterDirect ion.Output

oCmd.ExecuteNon Query()

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

If vReturn <> "-1" Then

FormsAuthentica tion.RedirectFr omLoginPage(oCm d.Parameters("@ 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
6393
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 button on the form. When the user hits enter the button is clicked. I have a second page mycsepp.aspx which has an asp button and a link button. When I hit enter neither of the button click events are triggered. If I tab to one of them and
0
1861
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 write something in text box and press Enter I invoke that button method ?!?! But this is not button I want to be default. I set tab orders and nothing always that button becomes default when I am on some text box on web form. How can I set default...
3
6744
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 following default properties: Height = 32px, Width = 144px. I declare the Width property in my control as... \\\
5
5418
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
4810
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 default. It's not there now. I found in the help index an isdefault property and tried to set it in code but it doesn't show up in the list when I type button1.isdef
3
3581
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 default look. Once I change a button's style to something else what is the style setting to revert them back to this default? EX: Button starts at default.
3
1564
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 context, the panel of a form which contains various buttons , are shown or hides. Now at design time i set the default button property to one of button. But when the form object is created in different context and set visibilty of default
15
12531
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 property. Where is it? Or mabye change the other thing,No?Thanks ! Simon
1
2164
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 messy it looks because I could not find the required button any other way but by using the id it is given in the source code. I tried every combination of nested 'findcontrol' methods I could think of, but none worked??!! It seems to be...
4
2980
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 week. The main form has a combo box that must have a value selected before anything else can happen. Once that value is selected, the 7 subforms are enabled, and also one of the fields is populated with the value from the main form. These subforms also...
0
8269
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
8642
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8512
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
7203
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
5576
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
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2630
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
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.