Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i have some fields on the page along with button and couple of textbox dropdown list , drop down list are auto post= true because there are getting data from database on page load and selected index change i wants to validate while button press to save , i don't wants to save null values to DB i tried requiredfield validater to validate but autopost back not working

kindly help me on that

Regards

Yogesh
Posted
Comments
DamithSL 5-May-14 5:46am    
update the question with related code, how you binding your drop down list? what is the initial value? can you show the aspx code of your RequiredFieldValidator and DropDownList ?
yogeshrrc 7-May-14 6:56am    
<table width="100%" border="0">
<tr>
<td colspan="5" align="center" height="15">
</td>
</tr>
<tr>
<td colspan="5" align="center">
</td>
</tr>
<tr>
<td width="10" height="15">
</td>
<td height="38" align="left">
Name:
</td>
<td align="left" style="width: 212px">
<asp:TextBox ID="txtname" runat="server" Height="15px" Width="150px"
ValidationGroup="postreqvalidate"><br />
<asp:requiredfieldvalidator runat="server"
errormessage="Name is Required" ID="chknm" ControlToValidate="txtname"
ValidationGroup="postreqvalidate">
</td>
<td height="33" align="left">
Email:
</td>
<td align="left">
<asp:TextBox ID="txtemail" runat="server" Height="15px" Width="150px"
TabIndex="1" ValidationGroup="postreqvalidate"><br />
<asp:requiredfieldvalidator runat="server" errormessage="Email is Required"
ControlToValidate="txtemail" ValidationGroup="postreqvalidate">
<asp:regularexpressionvalidator runat="server"
errormessage="Enter Correct Email id" ControlToValidate="txtemail"
ValidationGroup="postreqvalidate">
</td>
</tr>
<tr>
<td width="10" height="15">
</td>
<td height="45" align="left">
Telephone:
</td>
<td align="left" style="width: 212px">
<asp:TextBox ID="txtcontact" runat="server" Height="15px" Width="150px"
TabIndex="2" ValidationGroup="postreqvalidate">
<br />
<asp:requiredfieldvalidator runat="server" errormessage="Contact is Required"
ControlToValidate="txtcontact" ValidationGroup="postreqvalidate">
</td>
<td height="38" align="left">
Looking For :
</td>
<td align="left">
<asp:DropDownList ID="DDLlooking" runat="server" Width="150px" TabIndex="3"
ValidationGroup="postreqvalidate">
<asp:ListItem>Select
<asp:ListItem>Buy
<asp:ListItem>Lease

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="DDLlooking"
ErrorMessage="Please Select What are You Looking For ?" InitialValue="Select"
ValidationGroup="postreqvalidate">
<br />
</td>
</tr>
<tr>
<td width="10" height="15">
</td>
<td height="38" align="left">
Property Type :
</td>
<td align="left" style="width: 212px">
<asp:DropDownList ID="DDLPType" runat="server" Width="150px" TabIndex="4"
AutoPostBack="True" ValidationGroup="postreqvalidate">
<asp:ListItem>Select

1 solution

Do provide ValidationGroup to your dropdown and also to your RequiredField Validator

You can go through this code for javascript validation :


function manageValidation()
{

Validate the Page:
// validate all the validation that are present in the page.

Page_ClientValidate();

Validate the Page having certain validation Group:
// validate all the validation that are present in the page with this validation group.

Page_ClientValidate('ValidationGroup');

Get Is the page valid:
// Check wheather the page is valid or not

var pageValidated = Page_IsValid;
 if (pageValidated)
{
// Write some custom messages like

alert('Thanks for signing up with us. we will send your password to respective mail account');

}
else
{

// Other messages..

}

Enable or disable any validation :

// disable a certion validation
// ValidatorEnable(Control Name, status)

ValidatorEnable('requiredvalidatorTxtLastName', false)

// Enable some validation.

ValidatorEnable('requiredvalidatorTxtUserName', true)

Force Validation:

// Attach a certion validation with the control

ValidatorHookupControl('txtUserName', 'requiredvalidatorTxtUserName')

// Validate a certain validation.

ValidatorValidate('requiredvalidatorTxtUserName')

}
 
Manual Validation :
If you want to make the validation false of the page for any customize javascript Code you can do it as follows.

function checkPoints(sender,args)
{
  if(document.getElementById('txtPoints').value == (parseInt(    document.getElementById('txtBasicPoint').value) * 2)
   {
     args.isValid = false;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900