Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2009, 12:42 PM
Authorized User
 
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
Post I need help on custom required field validation, reall urgent please

I am a rookie programmer,
I am trying to create a requiredfield validator using the custom control available in .Net. I know about the inbuilt validators, but the case is that I need to create custom server side validators, therefore I dont want to mix the inbuilt client side validation controls that come with dotnet and the custom server side validators that I need to build. This is why I need to create a custom serverside textbox required field validator. But all efforts failed.THis is what I tried.

protected void e_serverValidate(................................. ... args)
{
if(TextBox1.Text.Trim()=="")
args.IsValid=false;
else
args.isValid=true;
}
Please how am I suppose to write the appriopriate code . Csharp, thank you
 
Old March 19th, 2009, 03:42 AM
Registered User
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Default

y cant u try through scripts lik

<script runat="server">
Sub user(source As object,args As ServerValidateEventArgs)
if len(args.Value)<8 or len(args.Value)>16 then
args.IsValid=false
else
args.IsValid=true
end if
End Sub
</script>


<html>
<body>

<form runat="server">
<asp:Label runat="server" Text="Enter a username: " />
<asp:TextBox id="txt1" runat="server" />
<asp:Button Text="Submit" runat="server"/>
<br />
<asp:Label id="mess" runat="server"/>
<br />
<asp:CustomValidator
ControlToValidate="txt1"
OnServerValidate="user"
Text="A username must be between 8 and 16 characters!"
runat="server"/>
</form>

</body>
</html>



or see this link

http://www.dotnetcurry.com/ShowArtic...ookieSupport=1
The Following User Says Thank You to pavithrashri For This Useful Post:
ysfkay (March 20th, 2009)
 
Old March 20th, 2009, 02:53 AM
Authorized User
 
Join Date: Jan 2009
Posts: 43
Thanks: 0
Thanked 2 Times in 2 Posts
Default from dinesh

function Validate()
{
var ctrl=document.getElementById("ur control id");

if(Trim(ctrl.value) == "")
{
alert("should not be empty!");
ctrl.focus();
return false;
}
return true;
}


on the click event of the submit button, use
onclick="if(!Validate())return false;"
__________________
dinesh s
 
Old March 20th, 2009, 03:03 AM
Authorized User
 
Join Date: Jan 2009
Posts: 43
Thanks: 0
Thanked 2 Times in 2 Posts
Default from dinesh

hi friends,
dont use asp:CustomValidator, try to write ur own code for validations.
__________________
dinesh s
 
Old March 20th, 2009, 01:46 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> dont use asp:CustomValidator, try to write ur own code for validations

Can you explain the reasonimg behind that statement? Why wouldn't you use the CustomValidator? It's a useful control if used properly....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 20th, 2009, 02:17 PM
Authorized User
 
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by dinesh View Post
hi friends,
dont use asp:CustomValidator, try to write ur own code for validations.
I thought if I used the custom validator, then I could reuse it and I wouldnt need to use labels to display the error messages...But do U suggest its better to write my own required field validator in a button click event instead...actually thats easier for me but I was studying a book asp 3.5 unleashed, its my first shot at asp, so I thot I could write a custom serverside required field validator that executes at the server along with the other custom server side validations I need to make..
 
Old March 20th, 2009, 02:19 PM
Authorized User
 
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
Default

I thought if I used the custom validator, then I could reuse it and I wouldnt need to use labels to display the error messages...But do U suggest its better to write my own required field validator in a button click event instead...actually thats easier for me but I was studying a book asp 3.5 unleashed, its my first shot at asp, so I thot I could write a custom serverside required field validator that executes at the server along with the other custom server side validations I need to make..
 
Old March 21st, 2009, 05:39 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
I need to create custom server side validators
Do you really need that? That is, do you really need to write your own validation control or do you simply want to use that control?

You could use a CustomValidator, set up a server side and optionally a client side validation function and be done with it. That's how you typically use the control.

What would be your reason for writing your own? Do you have specific validation rules you want to reuse across sites or pages and that you want to embed in your own control?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
required urgent help deb_kareng C# 1 September 5th, 2006 08:49 AM
Urgent help required! mani84 ADO.NET 1 May 19th, 2006 02:34 AM
Urgent help required AMP - Max Current BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 December 20th, 2004 11:26 PM
Required field dependent on another field... nkrukovsky Access VBA 3 January 14th, 2004 10:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.