最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - cancel server side submit funcion in asp.net with javascript - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question asked Mar 4, 2013 at 13:59 MistersMisters 1,3472 gold badges16 silver badges30 bronze badges 5
  • Ive re-read this 5 times and still cant find a question. – BenjaminPaul Commented Mar 4, 2013 at 14:01
  • Done, now its easier to find it – Misters Commented Mar 4, 2013 at 14:02
  • 1 you need to add logic to validate function....otherwise submit will never work..... – A.T. 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? – Misters Commented Mar 4, 2013 at 14:06
  • @Arun you were right, i miss something and it wasnt retuning anything – Misters Commented Mar 4, 2013 at 14:18
Add a ment  | 

3 Answers 3

Reset to default 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
}

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)
{
    ....
}

check this code

document.getElementById('YourFrom').onsubmit = function() {
    return false;
}
发布评论

评论列表(0)

  1. 暂无评论