Showing posts with label validate. Show all posts
Showing posts with label validate. Show all posts

Thursday, March 29, 2012

please gimme me a regular expression for date (dd-MMM-yyyy)

please help me as i have to validate a text box for date...check out this site: http://www.regexlib.com/
"pavan" wrote:

Quote:

Originally Posted by

please help me as i have to validate a text box for date...
>
>

Saturday, March 24, 2012

Please Help ! Validation Date ?

How can i validate a valid date when user enter the text into TextBox?Hi,

by using a CompareValidator.


<asp:TextBox ID="txtDate" runat="server" />
<asp:CompareValidator ControlToValidate="txtDate" Operator="DataTypeCheck" Type="Date" ErrorMessage="Please enter a valid date" runat="server" ID="cmpValtxtDate" />

Please help about Javascript for Asp.net Button

I have to validate so many controls at a time.I dont know what to Write in ControltoValidateProperty property in this case.So I went for writing Javascript function.

I wrote a function in javascript called "validateform" which checks all controls and validates the form.

Now when User clicks Submit Button I want to use this function.
The Problem is When i included that code in Button.attributes.add(...),Its giving me errormessages but also executing the server side code for button.

please help me

thxHow are you calling the Javascript function, from an OnClick event in the submit button or from an onSubmit call from the form. In either case you need to return false from the javascript function if a field does not validated. This will prevent the form from posting back and executing the server side code. If you could provide a code example, it would be easier for me to determine what is going wrong.
this is sample code

javascript :


function va()
{
if(document.all.p_title1.value=="")
{
alert("Team Name required");
return false;
}
else
return true;
}

Page Load :

ContinueButton.Attributes.Add("onclick","va();");

Button Server Event :


private void ContinueButton_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("SelectMaterial.aspx");

}

thx
I noticed the other day that if you don't specify that you want a value returned in the onclick event as well as returning the value from the function that the form postsback to the server regardless of the Javascript function return value, with that said, all you need to do is change you attributes.add statement like so.


ContinueButton.Attributes.Add("onclick","return va();");

That should solve the postback problem.
thank you very much.
It worked

Friday, March 16, 2012

please help me with validation

Hi, I am trying to validate 3 HtmlInputCheckBox controls:
<input type="checkbox" id="cbx1" runat="server">
<input type="checkbox" id="cbx2" runat="server">
<input type="checkbox" id="cbx3" runat="server">
<asp:button id="validate" Text="OK" runat="server"/>
<asp:ValidationSummary id="valsummary" ShowSummary="False" ShowMessageBox="True" runat="server"/>
I need at least one of them to be checked and popup a messagebox (as of the validationsummary control) that tells the user if no checkbox is checked.
I appreciate your help!
Sincerely,
PeleP
There is no validator supplied with ASP.NET that can evaluate an individual checkbox. You have several choices:
1. Use a CustomValidator. Create your own client-side code to handle the evaluation. After all, to show the messagebox, you *must* have client-side validation. (Its just a requirement of the validator controls.)
2. Replace your checkboxes with a CheckBoxList control. The RequiredFieldValidator can detect that its blank and report an error. This is the easiest solution, but doesn't work if you have a format that doesn't match what the CheckBoxList allows.
3. Switch to an alternative validation system which can handle checkboxes. MyProfessional Validation And More supplies 25 validators including several involved for creating this case. You would use my MultiConditionValidator like this:
<vam:MultiConditionValidator id="MCV1" runat="server" ErrorMessage="Please select one" Operator="OR">
<Conditions>
<vam:CheckStateCondition ControlIDToEvaluate="cbx1" Checked="True" />
<vam:CheckStateCondition ControlIDToEvaluate="cbx2" Checked="True" />
<vam:CheckStateCondition ControlIDToEvaluate="cbx3" Checked="True" />
</Conditions>
</vam:MultiConditionValidator>
This will generate client-side support. It supports many more browsers than ASP.NET 1.x validation does. And its message box option shown when the user submits will show the error message.
Hi! Thanks for your reply!

I do not think the RequiredFieldValidator control works with checkboxlist controls. Maybe it does in "asp.net" 2.0?

Your validation controls look interesting but I think I will try to do it myself.
It seems to be a little complicated though, but I will give it a go.

Thanks anyway!

Sincerely,
PeleP
The RequiredFieldValidator does work with the CheckBoxList and RadioButtonList. It does not work with ordinary CheckBox and RadioButton controls.
strange... i have tried that, and i cannot make it work. can you give me a quick example how you would do it?
this is what i have learned:
<asp:checkboxlist id="cb1" runat="server">
...items...
</asp:checkboxlist>
<asp.requiredfieldvalidator id="rfv" controltovalidate="cb1" runat="server"/>
so, are you sure? this is the last time... i will try to not disturb you further with stupid questions...
Sincerely,
PeleP
It is my understanding that's how to set it up. The RequiredFieldValidator has a property called InitialValue which has a string that is the text representing "blank". It defaults to "". When evaluating any type of list control, if there is no selection, the control has a value of "" which should match to InitialValue="".
There is one more piece. Each <asp:ListItem> has a Value property too. These must be assigned to something other than "".
<asp:ListItem value="1">text here</asp:ListItem>

Sorry. The RequiredFieldValidator does NOT word with the CheckboxList.

Here's why -- Remember that the builtin validation controls also render client script. It gets the required validation property from the value attribute of the HTML element that gets rendered on the client. Since an HTML value attribute can't be two things at once, the validated control must have a single logical value on the client.

This is why RadioButtonList can be validated, but CheckBoxList cannot


Hi Lee,

You are correct. I don't know where my head was when I was writing those posts. I suspect I confused the RadioButtonList's support with the CheckBoxList. Oh well. Thanks for clearing it up.


Hello, thank you both for following up this post. Now I understand why it is not possible, so I can and will leave it for now. Maybe the new asp.net 2.0 can give a solution to this!? I will look into that later.

Anyway, I temporarily solved it by using ordinary CheckBox's and have validated them using some client code.

Thanks for your help!

Sincerely, PeleP


Yes, there are workarounds, thank goodness. Probably the easiest is to create a customvalidator with both server and client-side code.

ASP 2.0 does not provide a solution. Understand, the inability to validate the CheckBoxList never really was a limitation of ASP in the first place. It's really caused by the limitations of HTML. (Remember, no matter what, the server still has to render HTML at the end of the whole deal.) There is no value= attribute of HTML checkboxes that let them determine the state of other checkboxes. Therefore, a built-in ASP validator couldn't automatically render "generic" client-side code for it.