2

I also made this question before but the problems remains here:

I have this code:

<asp:Button ID="CrearCuenta" UseSubmitBehavior="false" OnClientClick="return validate()" runat="server" Text="Ready" />

The javascript code:

function validate()
{
return false;
}

But in case that it return true, how do i execute de server side onclick function?? Thats what i cannot figure out. I know that similars question have been posted before, but none answer the question above.

5
  • Ive re-read this 5 times and still cant find a question. Commented Mar 4, 2013 at 14:01
  • Done, now its easier to find it Commented Mar 4, 2013 at 14:02
  • 1
    you need to add logic to validate function....otherwise submit will never work..... Commented Mar 4, 2013 at 14:04
  • It has it. it returns false if the validation fail. Ive tried athousands times and returns false if fails. So, whats the problem? Commented Mar 4, 2013 at 14:06
  • @Arun you were right, i miss something and it wasnt retuning anything Commented Mar 4, 2013 at 14:18

3 Answers 3

5

I hope, here is what you need:

<asp:Button ID="CrearCuenta" UseSubmitBehavior="false" 
OnClientClick="return validate()" OnClick="CrearCuenta_Click" 
runat="server" Text="Ready" />

Javascript:

function validate()
{
    if()
        return false;  //if validation fails
    else
        return true;
}

Server Side:

protected void CrearCuenta_Click(object sender, EventArgs e)
{
    //Put server side processing here
}
Sign up to request clarification or add additional context in comments.

Comments

3

Have you added the server side event handler?

In your page code:

<asp:Button ID="CrearCuenta" OnClick="btn_Click"....

In your code-behind:

protected void btn_Click(object sender, EventArgs e)
{
    ....
}

1 Comment

I didnt not that the onclick property could be different from the ID value
0

check this code

document.getElementById('YourFrom').onsubmit = function() {
    return false;
}

1 Comment

so, that mean that the asp button could be a normal button, right? no a server side button

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.