 |
| 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
|
|
|
|

March 18th, 2009, 12:42 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 19th, 2009, 03:42 AM
|
|
Registered User
|
|
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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:
|
|
|

March 20th, 2009, 02:53 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 43
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
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
|
|

March 20th, 2009, 03:03 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 43
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
from dinesh
hi friends,
dont use asp:CustomValidator, try to write ur own code for validations.
__________________
dinesh s
|
|

March 20th, 2009, 01:46 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
>> 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
|
|

March 20th, 2009, 02:17 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by dinesh
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..
|
|

March 20th, 2009, 02:19 PM
|
|
Authorized User
|
|
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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..
|
|

March 21st, 2009, 05:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
 |