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?

NitinRank #455 · 5.5K reputationPosted Mar 16, 2015, 9:51 PM EDT
Anjali C64 reputationPosted Mar 16, 2015, 10:18 PM EDT
NitinRank #455 · 5.5K reputationPosted Mar 16, 2015, 10:28 PM EDT
Are you using different validation groups in this forms? Or have you separated this form into two validation group?
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 16, 2015, 10:39 PM EDT
Riddhi ValechaRank #794 · 2.9K reputationPosted Mar 16, 2015, 10:44 PM EDT
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.
}
}
Vikram AgrawalRank #4,713 · 329 reputationPosted Mar 17, 2015, 12:52 AM EDT
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:
Anjali C64 reputationPosted Mar 17, 2015, 1:47 AM EDT
Anjali C64 reputationPosted Mar 17, 2015, 1:51 AM EDT
NitinRank #455 · 5.5K reputationPosted Mar 17, 2015, 1:52 AM EDT
Vikram AgrawalRank #4,713 · 329 reputationPosted Mar 17, 2015, 1:56 AM EDT
don't you want it in ButtonClick?
then please tell me where do you want to invoke these functions?
Anjali C64 reputationPosted Mar 17, 2015, 2:03 AM EDT
<%@ 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>
Anjali C64 reputationPosted Mar 17, 2015, 2:08 AM EDT
NitinRank #455 · 5.5K reputationPosted Mar 17, 2015, 2:12 AM EDT
NitinRank #455 · 5.5K reputationPosted Mar 17, 2015, 2:19 AM EDT
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);
}
Anjali C64 reputationPosted Mar 17, 2015, 2:21 AM EDT
NitinRank #455 · 5.5K reputationPosted Mar 17, 2015, 2:28 AM EDT
Do like this
Place this tag under the
put the src location of the file in the src tag above.
Vikram AgrawalRank #4,713 · 329 reputationPosted Mar 17, 2015, 2:32 AM EDT
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.
Gowtham RajamanickamRank #57 · 29K reputationPosted Apr 4, 2015, 9:30 PM EDT