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!