preventing submission without entering fields
i have created registration form as well as login form and i want them to prevent submission without entering fields means i want the user should enter fields and then he should be allowed access. How can i achieve this?
Gowtham RajamanickamPosted Apr 5, 2015, 1:30 AM
Vikram AgrawalPosted Mar 17, 2015, 6:32 AM
try it once no need for serverside validation or any validation control
put here your javascript code -
your button code should be like this -
and put your server side code in Button1_Click in login.aspx.cs which will execute when all inputs are valid.
NitinPosted Mar 17, 2015, 6:28 AM
Do like this
Place this tag under the
put the src location of the file in the src tag above.
Anjali CPosted Mar 17, 2015, 6:21 AM
NitinPosted Mar 17, 2015, 6:19 AM
In the .aspx write this code
In the .aspx.cs write this code
//Following statement is used to call pre-defined javascript function
protected void btnServerSide_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "myFunction", "myFunction();", true);
}
NitinPosted Mar 17, 2015, 6:12 AM
Anjali CPosted Mar 17, 2015, 6:08 AM
Anjali CPosted Mar 17, 2015, 6:03 AM
<%@ Page Title="" Language="C#" MasterPageFile="~/Master1.Master" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="ArtsDeals.Registration" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.style1
{
text-align: left;
width: 143px;
}
.style2
{
text-align: left;
height: 30px;
width: 143px;
}
.style3
{
height: 30px;
}
style>
asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div style="width: 553px">
<table style="width: 515px; height: 283px;">
<tr>
<th class="style1">
First Nameth>
<td>
<asp:TextBox ID="txtFName" runat="server" CausesValidation="True">asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtFName" ErrorMessage="Please enter First Name"
ForeColor="Red">asp:RequiredFieldValidator>
td>
tr>
<tr>
<th class="style1">
Middle Nameth>
<td>
<asp:TextBox ID="txtMName" runat="server" CausesValidation="True">asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtMName" ErrorMessage="Please enter Middle name"
ForeColor="Red">asp:RequiredFieldValidator>
td>
tr>
<tr>
<th class="style1">
Last Nameth>
<td>
<asp:TextBox ID="txtLName" runat="server" CssClass="Validators"
CausesValidation="True">asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtLName" ErrorMessage="Please enter Last Name"
ForeColor="Red">asp:RequiredFieldValidator>
td>
tr>
<tr>
<th class="style1">
Date Of Birthth>
<td>
<asp:TextBox ID="txtDOB" runat="server" ControlToValidate="TextBox5"
CssClass="Validators" CausesValidation="True">asp:TextBox>
<asp:CalendarExtender ID="txtDOB_CalendarExtender" runat="server"
Enabled="True" TargetControlID="txtDOB">
asp:CalendarExtender>
td>
tr>
<tr>
<th class="style1">
Mobile Noth>
<td>
<asp:TextBox ID="txtMob" runat="server" CausesValidation="True">asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server"
ControlToValidate="txtMob" ErrorMessage="MObileNO Required"
ForeColor="Red" ValidationExpression="^((\\+91-?)|0)?[0-9]{10}$">asp:RegularExpressionValidator>
td>
tr>
<tr>
<th class="style1">
EmailIdth>
<td>
<asp:TextBox ID="emailtxt" runat="server" CausesValidation="True">asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server"
ControlToValidate="emailtxt" CssClass="Validators"
ErrorMessage="Emailid Required" ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">asp:RegularExpressionValidator>
td>
tr>
<tr>
<th class="style1">
Genderth>
<td>
<asp:RadioButtonList ID="txtGender" runat="server" CssClass="Validators"
Height="16px" RepeatDirection="Horizontal" Width="188px"
CausesValidation="True">
<asp:ListItem>Maleasp:ListItem>
<asp:ListItem>Femaleasp:ListItem>
asp:RadioButtonList>
td>
tr>
<tr>
<th class="style2">
Passwordth>
<td class="style3">
<asp:TextBox ID="txtPswrd" runat="server" TextMode="Password"
CausesValidation="True">asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator8" runat="server"
ControlToValidate="txtPswrd" CssClass="Validators"
ErrorMessage="Password must contain: Minimum 8 characters atleast 1 Alphabet and 1 Number"
ForeColor="Red"
ValidationExpression="^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$">asp:RegularExpressionValidator>
td>
tr>
<tr>
<th class="style1">
Verify Passwordth>
<td>
<asp:TextBox ID="txtVerify" runat="server" TextMode="Password"
CausesValidation="True">asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txtPswrd" ControlToValidate="txtVerify"
CssClass="Validators" ErrorMessage="*" ForeColor="Red">asp:CompareValidator>
td>
tr>
table>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Register" style="font-weight: 700" />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
asp:ToolkitScriptManager>
div>
asp:Content>
Vikram AgrawalPosted Mar 17, 2015, 5:56 AM
don't you want it in ButtonClick?
then please tell me where do you want to invoke these functions?
NitinPosted Mar 17, 2015, 5:52 AM
Anjali CPosted Mar 17, 2015, 5:51 AM
Anjali CPosted Mar 17, 2015, 5:47 AM
Vikram AgrawalPosted Mar 17, 2015, 4:52 AM
Hi Anjali,
put all login validation code in one javascript function i.e. LoginValidation () and return false if any of validation gets fails and return true if all inputs are valid. Do the samething for Registration also
and call this function on button's OnClientClick event like below:
Riddhi ValechaPosted Mar 17, 2015, 2:44 AM
Instead, make a validating method in code file (aspx.cs) page.
Eg -
private String Validate()
{
if(txt_FirstName.text.Lenght > 0)
{
if(txt_LastName.text.lenght > 0)
{
return null;
}
else return "Enter Last Name.";
}
else return "Enter First Name.";
}
--
Add all the fields you have on your page.
------
Call this in button click
--
private void button1_click ()
{
if(Validate() == null)
{
// Insert.
}
}
Khargesh RajputPosted Mar 17, 2015, 2:39 AM
NitinPosted Mar 17, 2015, 2:28 AM
Are you using different validation groups in this forms? Or have you separated this form into two validation group?
Anjali CPosted Mar 17, 2015, 2:18 AM
NitinPosted Mar 17, 2015, 1:51 AM