<asp:TextBox ..... class="someBox" />
<asp:Button .... class="someButton" />
$('.someButton').click( function () {
var value = $('.someBox').val();
if (value == "") {
alert("Box is empty");
}
});
or another way
<asp:TextBox ..... class="someBox" />
<asp:Button .... class="someButton" />
<div id="validation"></div>
$('.someButton').click( function () {
var value = $('.someBox').val();
if (value == "") {
$('#validation').html("Please fill in the box");
}
});
Please post your code for us to help!!
Mark Answered if it helps - Good luck!
Cheers!
Design And Align - Rob
Basically i want to use Javascript pageMethod or asyc call to server side method and based on the result i want to validate the control. Is it possible ?
Right now i don't have a code.
Depending on the solution i will design the Project.
I have one custom validator and which is calling javascript function in which i am calling Pagemethod or async call and that page method return bool value. based on that bool value i want to make custom validator to validate the control.
Is it possible ? if yes than can you please provide me some article ?
patel.jay.40
Member
17 Points
24 Posts
how to do client side validation calling server side method ?
Apr 14, 2012 11:43 PM|LINK
I want to do client side validation using javascript. Is there a way to do that ?
Jay Patel
bakra
Member
342 Points
59 Posts
Re: how to do client side validation calling server side method ?
Apr 14, 2012 11:57 PM|LINK
Look at the example in the following link:
http://www.c-sharpcorner.com/UploadFile/purankaushal/103222006013805AM/1.aspx
Please "Mark as Answer" if this helped you
robwscott
Star
8079 Points
1491 Posts
Re: how to do client side validation calling server side method ?
Apr 15, 2012 12:00 AM|LINK
what do you want to validate?
<asp:TextBox ..... class="someBox" /> <asp:Button .... class="someButton" /> $('.someButton').click( function () { var value = $('.someBox').val(); if (value == "") { alert("Box is empty"); } });or another way
<asp:TextBox ..... class="someBox" /> <asp:Button .... class="someButton" /> <div id="validation"></div> $('.someButton').click( function () { var value = $('.someBox').val(); if (value == "") { $('#validation').html("Please fill in the box"); } });Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
robwscott
Star
8079 Points
1491 Posts
Re: how to do client side validation calling server side method ?
Apr 15, 2012 12:09 AM|LINK
or a more classy way is to use jquery modal - this is from one of my validations on my blog
validates that the textbox isn't empty as well as a valid email address
<asp:Button ..... class="ButtonUnsubscribe" /> <asp:TextBox ..... class="unsubscribeTextBox" /> <div id="dislog-message-Error" title="Error" style="display:none;"></div> $('.ButtonUnsubscribe').click(function () { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var error = ""; var emailFlag = false; var value = $('.unsubscribeTextBox').val(); if (value === "") { error = "Please enter an email address to unsubsribe."; errorFlag = true; } else { if (reg.test(value) == false) { error = "Please enter a valid email address."; errorFlag = true; } } if (errorFlag) { $('#dialog-message-Error').html('<div style="padding:5px;"><span style="line-height:18px;">' + error + '</span> </div>').dialog( { modal: true, draggable: false, resizable: false, height: 'auto', show: 'slide', buttons: { Ok: function () { $(this).dialog('close'); } } }); return false; } return true; });Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
patel.jay.40
Member
17 Points
24 Posts
Re: how to do client side validation calling server side method ?
Apr 15, 2012 12:18 AM|LINK
Basically i want to use Javascript pageMethod or asyc call to server side method and based on the result i want to validate the control. Is it possible ?
Right now i don't have a code.
Depending on the solution i will design the Project.
THanks for reply.
Jay Patel
robwscott
Star
8079 Points
1491 Posts
Re: how to do client side validation calling server side method ?
Apr 15, 2012 12:25 AM|LINK
based on what result? what are you passing back from the webmethod?
these are both good articles on how to return data, rather a string, object, etc.
http://www.dotnetfunda.com/articles/article1127-consuming-web-service-webmethod-from-jquery-in-aspnet.aspx
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
patel.jay.40
Member
17 Points
24 Posts
Re: how to do client side validation calling server side method ?
Apr 15, 2012 12:45 AM|LINK
Thanks for reply.
I have one custom validator and which is calling javascript function in which i am calling Pagemethod or async call and that page method return bool value. based on that bool value i want to make custom validator to validate the control.
Is it possible ? if yes than can you please provide me some article ?
Thanks
Jay Patel
robwscott
Star
8079 Points
1491 Posts
Re: how to do client side validation calling server side method ?
Apr 15, 2012 03:47 AM|LINK
can you please elaborate on to what the value is?
are you passing a parameter to the web method? if so what is it?
what is the statement in the web method that you are checking?
example: if (someVariable > 100) { return true; }
you have to be a little more descriptive when you write your posts. it makes it easier for me and others to help you.
Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
ramiramilu
All-Star
98053 Points
14516 Posts
Re: how to do client side validation calling server side method ?
Apr 15, 2012 10:48 AM|LINK
Client Call backs - http://msdn.microsoft.com/en-us/library/ms178208.aspx
Thanks,
JumpStart
patel.jay.40
Member
17 Points
24 Posts
Re: how to do client side validation calling server side method ?
Apr 15, 2012 11:41 PM|LINK
I found the solution.
http://www.junnark.com/junnark/Blog/Detail/1
Thanks all for your kind support.
Jay Patel