I am trying to make a signup page in my asp.net project where I am using SQL Server for my project. But the problem is that the data is not going to the database on clicking signup button.
Here is my code which I have tried for usersignup.aspx, usersignup.aspx.cs, web.config.
usersignup.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="usersignup.aspx.cs" Inherits="BookManagement.usersignup" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="container">
<div class="row">
<div class="col-md-8 mx-auto">
<div class="card" style="border-radius:30px;background: #e9efef;">
<div class="card-body">
<div class="row">
<div class="col">
<center>
<img src="imgs/generaluser.png" style="width:90px;height:90px;text-align:center;vertical-align:middle;"/>
</center>
</div>
</div>
<div class="row">
<h4 style="text-align:center;">User SignUp</h4>
</div>
<div class="row">
<div class="col">
<hr>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Full Name : </label>
<div class="form-group">
<asp:TextBox CssClass="form-control" ID="TextBox1" runat="server" Placeholder="Full Name"></asp:TextBox>
</div>
</div>
<div class="col-md-6">
<label>Date Of Birth : </label>
<div class="form-group">
<asp:TextBox CssClass="form-control" ID="TextBox2" runat="server" Placeholder="Date" TextMode="Date"></asp:TextBox>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<label>Contact NO : </label>
<div class="form-group">
<asp:TextBox CssClass="form-control" ID="TextBox3" runat="server" Placeholder="Contact No" TextMode="Number"></asp:TextBox>
</div>
</div>
<div class="col-md-6">
<label>Email : </label>
<div class="form-group">
<asp:TextBox CssClass="form-control" ID="TextBox4" runat="server" Placeholder="Email" TextMode="Email"></asp:TextBox>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md-4">
<label>State </label>
<div class="form-group">
<asp:DropDownList class="form-control" ID="DropDownList1" runat="server">
<asp:ListItem Text="Select" Value="Select" />
<asp:ListItem>Arunachal Pradesh</asp:ListItem>
<asp:ListItem>Andra Pradesh</asp:ListItem>
<asp:ListItem>Assam</asp:ListItem>
<asp:ListItem>Bihar</asp:ListItem>
<asp:ListItem>Chhattisgarh</asp:ListItem>
<asp:ListItem>Rajasthan</asp:ListItem>
<asp:ListItem>Goa</asp:ListItem>
<asp:ListItem>Gujarat</asp:ListItem>
<asp:ListItem>Haryana</asp:ListItem>
<asp:ListItem>Himachal Pradesh</asp:ListItem>
<asp:ListItem>Jammu and Kashmir</asp:ListItem>
<asp:ListItem>Jharkhand</asp:ListItem>
<asp:ListItem>Karnataka</asp:ListItem>
<asp:ListItem>Kerela</asp:ListItem>
<asp:ListItem>Madhya Pradesh</asp:ListItem>
<asp:ListItem>Maharashtra</asp:ListItem>
<asp:ListItem>Odisa</asp:ListItem>
<asp:ListItem>Sikkim</asp:ListItem>
<asp:ListItem>Punjab</asp:ListItem>
<asp:ListItem>Tamil Nadu</asp:ListItem>
<asp:ListItem>West Bengal</asp:ListItem>
</asp:DropDownList>
</div>
</div>
<div class="col-md-4">
<label>City : </label>
<div class="form-group">
<asp:TextBox Class="form-control" ID="TextBox6" runat="server" Placeholder="City"></asp:TextBox>
</div>
</div>
<div class="col-md-4">
<label>PinCode : </label>
<div class="form-group">
<asp:TextBox CssClass="form-control" ID="TextBox7" runat="server" Placeholder="Pincode" TextMode="Number"></asp:TextBox>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col">
<label>Full Address: </label>
<div class="form-group">
<asp:TextBox CssClass="form-control" ID="TextBox5" runat="server" Placeholder="Full Address" TextMode="MultiLine"></asp:TextBox>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col">
<span class="badge rounded-pill bg-warning text-dark">New Login Credentials</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<label>Member ID : </label>
<div class="form-group">
<asp:TextBox Class="form-control" ID="TextBox8" runat="server" Placeholder="Member ID"></asp:TextBox>
</div>
</div>
<div class="col-md-6">
<label>Password : </label>
<div class="form-group">
<asp:TextBox CssClass="form-control" ID="TextBox9" runat="server" Placeholder="Password" TextMode="Password"></asp:TextBox>
</div>
</div>
</div>
<div class="row">
<div class="col" style="width:100%;">
<br>
<div class="form-group">
<center>
<%--<asp:Button class="btn btn-success btn-block btn-lg" style="width:510px;" ID="SignUp" runat="server" Text="Sign Up" OnClick="SignUp_Click" />--%>
<asp:Button class="btn btn-success btn-block btn-lg" style="width:510px;" ID="Button1" runat="server" Text="SignUp" OnClick="Button1_Click" />
</center>
</div>
</div>
</div>
</div>
</div>
<< Back To Home
</div>
</div>
</div>
</asp:Content>
Here is my usersignup.aspx.cs file
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
namespace BookManagement
{
public partial class usersignup : System.Web.UI.Page
{
string strcon = WebConfigurationManager.ConnectionStrings["con"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (checkMemberExists())
{
Response.Write("<script>alert('Member Already Exists.Try Again!!!');</script>");
}
else
{
signUpNewMember();
}
}
bool checkMemberExists()
{
try
{
SqlConnection con = new SqlConnection(strcon);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("SELECT * FROM member_master_tabel WHERE member_id='"+TextBox8.Text.Trim()+"';", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count >= 1)
{
return true;
}
else
{
return false;
}
//cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('signup is successful. Go to the login page.');</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
return false;
}
}
void signUpNewMember()
{
try
{
SqlConnection con = new SqlConnection(strcon);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("INSERT INTO member_master_tabel(full_name,dob,contact_no,email,state,city,pincode,full_address,member_id,password,account_status)" +
"VALUES(#full_name,#dob,#contact_no,#email,#state,#city,#pincode,#full_address,#member_id,#password,#account_status)", con);
//SqlCommand cmd = new SqlCommand("INSERT INTO member_master_tabel VALUES('abhay', '11-10-2018', '1234567890', 'mail#demo.com', 'Gujarat', 'Ahmedabad', '380001', 'qwertytjfgnbvf', 'ts13', '456', 'pending');", con);
cmd.Parameters.AddWithValue("#full_name", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("#dob", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("#contact_no", TextBox3.Text.Trim());
cmd.Parameters.AddWithValue("#email", TextBox4.Text.Trim());
cmd.Parameters.AddWithValue("#state", DropDownList1.SelectedItem.Value);
cmd.Parameters.AddWithValue("#city", TextBox6.Text.Trim());
cmd.Parameters.AddWithValue("#pincode", TextBox7.Text.Trim());
cmd.Parameters.AddWithValue("#full_address", TextBox5.Text.Trim());
cmd.Parameters.AddWithValue("#member_id", TextBox8.Text.Trim());
cmd.Parameters.AddWithValue("#password", TextBox9.Text.Trim());
cmd.Parameters.AddWithValue("#account_status", "pending");
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>alert('signup is successful. Go to the login page.');</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}
}
}
}
Here is my web.config file :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="con" connectionString="Data Source=PROBOOK-HP\SQLEXPRESS;Initial Catalog=ebookDB;Integerated Security=true" />
</connectionStrings>
I am creating a modal in an aspx form which will add data in database. But it is showing this error
A page can have only one server-side Form tag.
I did the same in another file on same project where I created a Login page which worked completely fine. It also had 2 forms, the default one and the one I created. But here it is showing error although I have tried removing runat="server" from the second form but still no solution.
<body>
<form id="form1" runat="server">
<div>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top">
<button class="navbar-toggler" data-toggle="collapse" data-target="#collapse_target">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsiblenavbar">
<a class="navbar-brand" href="index.aspx">
<img src="logo.ico" class="img-responsive" /></a>
<ul class="navbar-nav ">
<li class="nav-item">
<a class="nav-link" href="index.aspx"><i class="fa fa-home"></i> home </a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.aspx"><i class="fa fa-sign-out"></i> logout </a>
</li>
<%--<asp:listview runat="server" id="listview1" --%>
</ul>
</div>
</nav>
<p></p>
<style>
p {
line-height: 5px;
}
</style>
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card" style="width: 18rem;">
<img src="user.png" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">profile info</h5>
<%--<p class="card-text" id="para1"><i class="fa fa-user-circle-o"></i> taimoor baig</p>--%>
<asp:Label ID="label1" CssClass="card-text fa fa-user-circle-o" runat="server"> </asp:Label>
<p class="card-text"><i class="fa fa-user-circle"></i> admin</p>
<p class="card-text"><i class="fa fa-clock-o"></i> last login : xx-xx-xxxx</p>
edit profile
</div>
</div>
</div>
<div class="col-md-8">
<div class="jumbotron" style="width: 100%; height: 100%;">
<h1>welcome admin</h1>
<div class="row">
<div class="col-md-6">
<iframe src="http://free.timeanddate.com/clock/i6ovwi4o/n106/szw160/szh160/hoc222/hbw6/cf100/hgr0/hcw2/hcd88/fan2/fas20/fdi70/mqc000/mqs3/mql13/mqw6/mqd94/mhc000/mhs3/mhl13/mhw6/mhd94/mmc000/mml5/mmw1/mmd94/hwm2/hhs2/hhl55/hhb18/hhw8/hms2/hml85/hmb18/hmw8/hmr7/hss3/hsl90/hsr5" frameborder="0" width="160" height="160"></iframe>
</div>
<div class="col-md-6">
<div class="card" <%--style="font-size: large;"--%>>
<div class="card-body" style="width: 20rem;">
<h5 class="card-title">new orders</h5>
<p class="card-text">here you can add new orders.</p>
new orders
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br />
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">brand</h5>
<p class="card-text">here you can manage brand.</p>
add brand
manage brand
</div>
</div>
</div>
<div class="col-md-4">
<div class="card" style="width: 20rem;">
<div class="card-body">
<h5 class="card-title">product</h5>
<p class="card-text">here you can manage products.</p>
add product
manage products
</div>
</div>
</div>
<div class="col-md-4">
<div class="card" style="width: 20rem;">
<div class="card-body">
<h5 class="card-title">market</h5>
<p class="card-text">here you can manage markets.</p>
add market
manage markets
</div>
</div>
</div>
<div class="col-md-4">
<div class="card" style="width: 20rem;">
<div class="card-body">
<h5 class="card-title">salesman</h5>
<p class="card-text">here you can manage salesman.</p>
add salesman
manage salesman
</div>
</div>
</div>
<div class="col-md-4">
<div class="card" style="width: 20rem;">
<div class="card-body">
<h5 class="card-title">vendor</h5>
<p class="card-text">here you can manage vendor.</p>
add vendor
manage vendors
</div>
</div>
</div>
</div>
</div>
<!-- modal of brand -->
<div class="modal fade" id="form_brand" tabindex="-1" role="dialog" aria-labelledby="examplemodallabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">add new brand</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="close">
<span aria-hidden="true">×</span>
</button>
</div>
<div runat="server" class="modal-body">
<form runat="server">
<div class="form-group" runat="server">
<label>brand name</label>
<%--<input type="text" class="form-control" name="brand_name" id="brand_name" placeholder="enter brand name"/>--%>
<asp:TextBox CssClass="form-control" ID="textbox1" runat="server">
enter brand name
</asp:TextBox>
</div>
<div class="form-group">
<label>brand sector name</label>
<%--<input type="text" class="form-control" id="brand_sector_name" placeholder="enter brand sector name"/>--%>
<asp:TextBox ID="textbox2" CssClass="form-control" runat="server">
enter brand sector name
</asp:TextBox>
<small id="brand_sector__error" class="form-text text-muted"></small>
</div>
<div class="form-group">
<label>vendor dealing</label>
<%--<input type="text" class="form-control" id="vendor_dealing" placeholder="enter vendor name"/>--%>
<asp:TextBox ID="textbox3" CssClass="form-control" runat="server">
enter vendor name
</asp:TextBox>
<small id="vendor_error" class="form-text text-muted"></small>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">close</button>
<button type="button" class="btn btn-primary">add</button>
</div>
</div>
</div>
</div>
I expect a webform with a modal displaying after pressing the "add brand" button
Looks like you have two form tag, 1 in master page and 1 in the page that throws the error.
Try to remove 1
I have to create a textbox and button dynamically on page load and on button click have to check the textbox value is not greater than the amount value give with radio for each row. For example - if value in radio is 500$ then textbox value should be greater than 500$ or equal if less then the button in this panel should be disabled.
<asp:Repeater runat="server" ID="RP_R"><ItemTemplate>
<div class="well">
<div class="row">
<div class="col-sm-12 ">
<label class="radio-inline" style="font-size:20px;margin-left:-1px;"><input type="radio" name="reward"><%# Eval("_amount") %> or more</label>
</div>
</div>
<div class="row" style="font-size:15px;" >
<hr/>
<div class="col-sm-5 col-xs-6" style="padding-left:20px;">
<label><%#Eval("name") %></label>
<p><%#Eval("details") %></p>
</div>
<div class="col-sm-offset-3 col-sm-3 col-xs-6">
<label>Estimated Delivery </label>
<p><%#Eval("estimated_delivery_date") %></p>
</div>
</div>
<div class="clearfix"></div>
<hr/>
<div class="row">
<div class="col-sm-12">
<label style="font-size:16px;padding-left:5px;" >Amount Raised</label>
</div>
</div>
<div class="row">
<div class="col-sm-10 col-xs-8">
<asp:TextBox runat="server" ID="txt_reward" CssClass="form-control"></asp:TextBox>
</div>
<div class="col-sm-2 col-xs-3">
<button type="button" class="btn btn-success" runat="server" id="btn_r">Continue</button>
</div>
</div>
</div>
</ItemTemplate></asp:Repeater>
Here I am implementing bootstrap tab control in asp.net application.
1) On click on next i want to go to next tab.
I want to make tab control working by clicking on tabs of tab control to go to next tab or by clicking on next button.
<form id="form1" runat="server">
<div class="container">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#personal">Personal Information</a></li>
<li><a data-toggle="tab" href="#professional">Professional Information</a></li>
<li><a data-toggle="tab" href="#accountinformation">User Account Infromation</a></li>
</ul>
<div class="tab-content">
<div id="personal" class="tab-pane fade in active">
<div class="form-group">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="col-sm-4">
<span class="Star-clr">*</span>First Name :
</div>
<div class="col-sm-8">
<asp:TextBox ID="txtName" runat="server" placeholder="First Name"</asp:TextBox>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="col-sm-2">
</div>
<div class="col-sm-10" style="float: right">
<asp:Button ID="btnNext" Width="150" runat="server" Text="NEXT" />
</div>
</div>
</div>
</div>
</div>
<div id="professional" class="tab-pane fade">
</div>
<div id="accountinformation" class="tab-pane fade">
</div>
</div>
</div>
</form>
Image of Tab control:
Create a button after your content divs and call function on this button
<input type="button" value="Next" onclick="ShowNextTab();" />
function ShowNextTab() {
if ($('.nav-tabs > .active').next('li').length == 0) //If you want to select first tab when last tab is reached
$('.nav-tabs > li').first().find('a').trigger('click');
else
$('.nav-tabs > .active').next('li').find('a').trigger('click');
}
Below is a complete solution
HTML
<form id="form1" runat="server">
<div class="container">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#personal">Personal Information</a></li>
<li><a data-toggle="tab" href="#professional">Professional Information</a></li>
<li><a data-toggle="tab" href="#accountinformation">User Account Infromation</a></li>
</ul>
<div class="tab-content">
<div id="personal" class="tab-pane fade in active">
<div class="form-group">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="col-sm-4">
<span class="Star-clr">*</span>First Name :
</div>
<div class="col-sm-8">
<asp:TextBox ID="txtName" runat="server" placeholder="First Name"></asp:TextBox>//close tag is missing
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="col-sm-2">
</div>
<div class="col-sm-10" style="float: right">
<asp:Button ID="btnNext" Width="150" runat="server" Text="NEXT" />
</div>
</div>
</div>
</div>
</div>
<div id="professional" class="tab-pane fade">
</div>
<div id="accountinformation" class="tab-pane fade">
</div>
<input type="button" value="Next" onclick="ShowNextTab();" />
<input type="button" value="Prev" onclick="ShowPrevTab();" />
</div>
</div>
</form>
JavaScript
function ShowNextTab() {
$('.nav-tabs > .active').next('li').find('a').trigger('click');
}
function ShowPrevTab() {
$('.nav-tabs > .active').prev('li').find('a').trigger('click');
}
I'm trying to get the value of the radio button clicked but so far the value is null. The code below has a couple of things going on:
1) when the button is clicked it should move the radio buttons to the left.
2) I need to the get value of which radio button is clicked
The first part works but I can't get the second part. This is my code:
<script>
$(document).ready(function(){
$("#form1").click(function(){
$("#list_of_btns").animate({left: '-150px'});
});
});
</script>
//this is the form for radio button...it must be centered to middle of the page
<div id="list_of_btns" style="padding-top: 80px; position:fixed;">
<div class="row" style="position:fixed;">
<div class="col-md-8 col-md-offset-4" style="position:fixed;">
<div class="list-group" style="position:fixed;">
<form role="radio_button_form" style="position:fixed;">
<div class="radio">
<label><input type="radio" value="male" name="method">male</label>
</div>
<div class="radio">
<label><input type="radio" value="female" name="method">female</label>
</div>
</form>
</div>
</div>
</div>
</div>
//this is the enter button.
<div class="row" style="padding-top: 80px; position:relative;">
<div class="col-md-8 col-md-offset-16" style="position:relative;">
<form id="form1" runat="server" style="position:relative;">
<asp:LinkButton class="btn btn-info" ID="getStarted_btn" runat="server" OnClick="btn_clicked" Text="Enter" />
</form>
</div>
</div>
This is where I am trying to get value of the radio button, in my c# code:
public void btn_clicked (object sender, EventArgs args)
{
Console.Out.WriteLine ("sdsfdsfdfsdf");
if (Request.Form["method"] != null)
{
string selectedGender = Request.Form["method"].ToString();
Console.Out.WriteLine (selectedGender);
}
}
Does anybody have any idea on what I'm doing wrong or is there a better way in achieving this?
I have edited your code and this is working.Plz check
<body>
<form id="form1" runat="server" style="position: relative;">
<div id="list_of_btns" style="padding-top: 80px; position: fixed;">
<div class="row" style="position: absolute;">
<div class="col-md-8 col-md-offset-4" style="position: fixed;">
<div class="list-group" style="position: fixed;">
<div class="radio">
<label>
<input type="radio" value="male" name="method">male</label>
</div>
<div class="radio">
<label>
<input type="radio" value="female" name="method">female</label>
</div>
</div>
</div>
</div>
</div>
<div class="row" style="padding-top: 80px; position: relative;">
<div style="position: relative;">
<asp:LinkButton class="btn btn-info" ID="getStarted_btn" runat="server" OnClick="btn_clicked" Text="Enter" />
</div>
</div>
</form>
Enclose the whole content inside single Form..