View Full Version : Client n Server side validation

01-08-2007, 07:17 PM
is there a way I could validate some data on the client side when user clicks a button and after validation do something which executes the code on buttons server side code btnSave_ServerClick(object sender, System.EventArgs e)

this is the html code n javascript for that button

<input type="button" value="Save" runat="server" id="btnSave" name="btnSave" onclick="ValidateNSubmit();">

function ValidateNSubmit()
var strarrAutoSell = "testingsubmit";
if( strarrAutoSell = "testingsubmit" )
return true;
return false;

mind it that I could not use "Submit" as form's submit is already used by another onclick event in the same page
and this is the server side function that I want to use..

private void btnSave_ServerClick(object sender, System.EventArgs e)
//here goes my func logic...

now in this current code client side validation is working but the return true is not letting that server side function to be called

01-08-2007, 10:19 PM
This is .net.
Why don't you just use a Validator?

01-09-2007, 07:02 AM
well I guess validators r not going to work in my case, as I've to pass a string to server side which it would use to perform some work

anyway In between I found an attribute "onserverclick" which I guess could be useful but somehow I'm unable to use it.

This is what I'm trying to do

//Line 139
<input id="btnSave" type="button" value="Save" runat="server" onserverclick="btnSave_ServerClick" onclick="Validate();">

the effect of this code is that whenever user clicks on the button, validate()
function executes smoothly but right after that it prompts this error in status bar

Error: Object expected
Line 139
char 1

01-09-2007, 03:29 PM
If you don't want to use a Validator (you can pass text and all that, but you do have to write more code), you can make a button have both a client script and a server script using onClientClick.

Was that what you were looking for?