Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Client n Server side validation

    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

    Code:
    <input type="button" value="Save" runat="server" id="btnSave" name="btnSave" onclick="ValidateNSubmit();">
    
    function ValidateNSubmit()
    {
    	var strarrAutoSell = "testingsubmit";
    	if( strarrAutoSell = "testingsubmit" )
    		return true;
    	else
    		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..

    Code:
    		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
    Last edited by uxair; 01-08-2007 at 07:19 PM.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    This is .net.
    Why don't you just use a Validator?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Dec 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    Code:
    //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

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.
    http://msdn2.microsoft.com/en-us/lib...ientclick.aspx

    Was that what you were looking for?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •