|
-
Mar 24th, 2004, 12:30 PM
#1
Thread Starter
Lively Member
can I have two separate forms in one page
Hi, I am trying two have two separate forms in one page like the New Users Registration forms and the Login forms. How do I handle both these forms.... I tried them the following way but no luck when I hit the login button it still asks for the fields in the register formss......Ur help will be appreciated
Code:
<script runat="server">
Sub Page_Load
End Sub
Sub btnLogin_Click(s As Object, Ev As EventArgs)
Dim conUsers As SqlConnection
Dim strInsert As String, count As Integer
Dim cmdLogin As SqlCommand
conUsers = New SqlConnection("")
cmdLogin = New SqlCommand("Select count(*) from NewUser where fldUserName = @luName and fldPassWord = @lpWord", conUsers)
cmdLogin.Parameters.Add("@luName", txtLoginName.Text)
cmdLogin.Parameters.Add("@lpWord", txtLoginPassWord.Text)
conUsers.Open
count = cmdLogin.ExecuteScalar()
If(count > 0)
Else
lblLoginErrMessage.Visible = TRUE
lblLoginErrMessage.Text = "Invalid Login"
End If
conUsers.Close
End Sub
Sub btnRegister_Click(sender As Object, e As EventArgs)
Dim conUsers As SqlConnection
Dim strInsert As String
Dim cmdCheck, cmdInsert As SqlCommand
Dim count As Integer
Dim strMessage As String
conUsers = New SqlConnection("")
cmdCheck = New SqlCommand("Select count(*) from NewUser where fldUserName = @uName", conUsers)
cmdCheck.Parameters.Add("@uName", txtUserName.Text)
conUsers.open()
count = cmdCheck.ExecuteScalar()
If(count > 0)
lblErrMessage.Visible=True
lblErrMessage.text = "The User Name already exists. Please Select a different user name"
conUsers.close()
Else
lblErrMessage.visible = false
strInsert = "Insert NewUser(fldFirstName, fldLastName, fldUserName, fldPassWord, fldAddress, fldCity, fldState, fldZip, fldCountry, fldEmail, fldPhone) Values (@fName, @lName, @uName, @pWord, @addr, @city, @state, @zip, @country, @email, @phone)"
cmdInsert = New SqlCommand(strInsert, conusers)
cmdInsert.Parameters.Add("@fName", txtFirstName.Text)
cmdInsert.Parameters.Add("@lName", txtLastName.Text)
cmdInsert.Parameters.Add("@uName", txtUserName.Text)
cmdInsert.Parameters.Add("@pWord", txtPassWord.Text)
cmdInsert.Parameters.Add("@addr", txtAddress.Text)
cmdInsert.Parameters.Add("@city", txtCity.Text)
cmdInsert.Parameters.Add("@state", txtState.Text)
cmdInsert.Parameters.Add("@zip", txtZip.Text)
cmdInsert.Parameters.Add("@country", "USA")
cmdInsert.Parameters.Add("@email", txtEmail.Text)
cmdInsert.Parameters.Add("@phone", txtPhone.Text)
cmdInsert.ExecuteNonQuery()
conUsers.Close()
End If
End Sub
</script>
<html>
<head>
</head>
<body>
<div align="center">
<form name="newuser" runat="server">
<table border="0" cellspacing="0" cellpadding="0" width="640">
<tr>
<td width = "320">
<table border="0" cellspacing="0" cellpadding="0" width="320">
<tr><td width="320" align="left" colspan="2" visible="false">
<asp:Label id="lblErrMessage" backcolor="yellow" forecolor="RED" visible="false" Runat="Server" /></td>
</tr>
<tr><td width="320" align="left" colspan="2"><br/>
<img id="newuser" src="/images/images/NewUserReg.gif" ></td>
</tr>
<table width="320" bgcolor="#B0CEF8" border="0" cellpadding="3" cellspacing="3">
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td align="Right" valign="Center"><p>First Name *</p></td>
<td><p>
<Asp:RequiredFieldValidator id="rfvFirstName" font-size="12" ControlToValidate = "txtFirstName"
ErrorMessage="Please enter your FirstName" runat="Server" />
<asp:TextBox id="txtFirstName" runat="server"></asp:TextBox></p></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td align="Right"><p>Last Name *</p></td>
<td><p>
<Asp:RequiredFieldValidator id="rfvLastName" font-size="12" ControlToValidate = "txtLastName"
ErrorMessage="Please enter your LastName" runat="Server" />
<asp:TextBox id="txtLastName" runat="server"></asp:TextBox></p></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td align="Right"><p>UserName *</p></td>
<td><p>
<Asp:RequiredFieldValidator id="rfvUserName" font-size="12" ControlToValidate = "txtUserName"
ErrorMessage="Please enter your UserName" runat="Server" />
<asp:TextBox id="txtUserName" runat="server"></asp:TextBox></p></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td align="Right"><p>PassWord *</p></td>
<td><p>
<Asp:RequiredFieldValidator id="rfvPassWord" font-size="12" ControlToValidate = "txtPassWord"
ErrorMessage="Please enter your PassWord" runat="Server" />
<asp:TextBox textmode="password" id="txtPassWord" runat="server"></asp:TextBox></p></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td align="Right"><p>Retype-PassWord *</p></td>
<td><p>
<Asp:RequiredFieldValidator id="rfvRePassWord" font-size="12" ControlToValidate = "txtRePassWord"
ErrorMessage="Please enter your PassWord" runat="Server" />
<asp:TextBox textmode="password" id="txtRePassWord" runat="server"></asp:TextBox></p></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td align="Right"><p>Address *</p></td>
<td><p>
<Asp:RequiredFieldValidator id="rfvAddress" font-size="12" ControlToValidate = "txtAddress"
ErrorMessage="Please enter your Address" runat="Server" />
<asp:TextBox id="txtAddress" runat="server"></asp:TextBox></p></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td align="Right"><p>City *</p></td>
<td><p>
<Asp:RequiredFieldValidator id="rfvCity" font-size="12" ControlToValidate = "txtCity"
ErrorMessage="Please enter your City" runat="Server" />
<asp:TextBox id="txtCity" runat="server"></asp:TextBox></p></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr>
<td align="Right"><p> State *</p></td>
<td><p>
<Asp:RequiredFieldValidator id="rfvState" font-size="12" ControlToValidate = "txtState"
ErrorMessage="Please enter your State" runat="Server" />
<asp:TextBox id="txtState" runat="server"></asp:TextBox></P></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td align="Right"><p>Zip *</p></td>
<td><p>
<Asp:RequiredFieldValidator id="rfvZip" font-size="12" ControlToValidate = "txtZip"
ErrorMessage="Please enter your Zip" runat="Server" />
<asp:TextBox id="txtZip" runat="server"></asp:TextBox></p></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td align="Right"><p>E-mail *</p></td>
<td><p>
<Asp:RequiredFieldValidator id="rfvEmail" font-size="12" ControlToValidate = "txtEmail"
ErrorMessage="Please enter your Email" runat="Server" />
<asp:TextBox id="txtEmail" runat="server"></asp:Textbox></p></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td align="Right"><p>Phone# </p></td>
<td><p>
<asp:TextBox id="txtPhone" runat="server"></asp:Textbox></p></td>
</tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td colspan="2" align="center">
<p><asp:Button id="btnRegister" onclick="btnRegister_Click" runat="server" Text="Register"></asp:Button></p></td>
</tr>
</table>
</td>
<td width="300" valign="top" align="right">
<table border="0" cellspacing="0" cellpadding="0" width="300">
<tr><td width="300" align="left" colspan="2" forecolor="RED" visible="False">
<asp:Label id="lblLoginErrMessage" backcolor="yellow" visible="false" forecolor="RED" Runat="Server" /></td>
</tr>
<tr><td width="300" align="left" colspan="2"><br/>
<img id="newuser" src="/images/images/userlogin.gif" ></td>
</tr>
<tr><td><table width="300" cellpaddng="0" cellspacing="0" bgcolor="#B0CEF8">
<tr><td colspan="2"> <p>Existing Users </p></td></tr>
<tr><td colspan="2"> <p>Enter your UserName and Password to Access Your Account</p></td></tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td width="300" align="left" colspan="2" >UserName:</td></tr>
<tr><td width="300" align="left" colspan="2"><Asp:textbox id="txtLoginName" Runat="Server" /></td></tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td width="300" align="left" colspan="2">PassWord:</td></tr>
<tr><td width="300" align="left" colspan="2" ><asp:textbox textmode="password" id="txtLoginPassWord" Runat="Server" /></td></tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td align="center">
<p><asp:Button id="btnLogin" onclick="btnLogin_Click" runat="server" Text="Login"></asp:Button></p></td>
<td align="Center">
<p><asp:hyperlink id="hypForgot" name="hypForgot" text="Forgot Your Password"
Runat="Server" /></td>
</tr>
</table></td></tr>
</table>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
-
Mar 24th, 2004, 12:37 PM
#2
Frenzied Member
ASP.NET Doesn't support multiple runat=server forms on the same page.
To handle this problem, you can place each form in a seperate panel control, then allow the user to easilly switch between the panels by clicking on a radio button.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Mar 24th, 2004, 01:05 PM
#3
Thread Starter
Lively Member
Hi memnoch,
Thanks for ur reply....I will try that but it looks like a bad way to do that.....Do we have any other option
-
Mar 24th, 2004, 06:59 PM
#4
PowerPoster
Have one form, but perform your own javascript validating. This would be the only other way I know. Or, you could do all the validating in your code and during a postback, check the values.
Better yet, make two seperate forms.....
-
Mar 24th, 2004, 10:37 PM
#5
I wonder how many charact
Better yet, make two seperate forms.....
Them there words is good advice!
-
Mar 25th, 2004, 08:05 AM
#6
Thread Starter
Lively Member
hi Hellswrath and nemroller,
Thanks for ur reply guyz....Yeah I will follow the javascript only....nemroller it is two separate forms only...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|