如果我单击按钮,我想运行我的Java Scriptcode进行验证 [英] I Want To Run My Java Scriptcode For Validate If I Click The Button

查看:84
本文介绍了如果我单击按钮,我想运行我的Java Scriptcode进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行我的java脚本代码验证,如果我点击按钮。但它不工作



< asp:Button ID =Button1runat =serverText =saveOnClick =Button1_ClickonOnClientClick =uservalid();/>

i want to run my java script code for validate if i click the button.but its not working

<asp:Button ID="Button1" runat="server" Text="save" OnClick="Button1_Click" onOnClientClick="uservalid();"/>

推荐答案

编辑:

OP评论说:这只是问题中的一个错字,实际上不在代码中

onOnClientClick 应该是 OnClientClick



编辑:



尝试2.



客户端点击不会做太多,因为无论如何都要发布页面。而不是OnClick =Button1_Click试试这个(或类似的)


The OP commented: This was just a typo in the question, not actually in the code
onOnClientClick should be OnClientClick



Attempt 2.

The client click will not do much because the page is being posted anyway. Instead of OnClick="Button1_Click" try this (or similar)
<asp:Button ID="Button1"
   runat="server" Text="save"
   onOnClientClick="uservalid(this);"/>

<script ...>
  function uservalid(control){
     controle.preventDefault(); //stops the postback.
     bool isValid = someotherstuff();
     if(isValid)
       __doPostBack(control.id,null);
  }
</script>





这是没有经过测试,但之前我做过类似的事。回发函数应该会触发click事件。



你仍然需要在后面的代码中连接click事件但是有autopostback = false所以for仅在用户验证通过后才会发布



This is not tested but I've done similar before. The postback function should cause the click event to be triggered.

You will still have to wire up the click event in the code behind but have autopostback = false so the for is only posted if the user validation passes


您可以通过jquery完成所有操作吗?





var validateFunction = function(){

//你的验证函数就在这里。

}



//把它放在你的函数initalizer中。
You could do it all solely via jquery?


var validateFunction = function(){
//your validate function goes here.
}

// put this in your functions initalizer.


('#idOfButton')。on('click',validateFunction);
('#idOfButton').on('click', validateFunction);


这篇关于如果我单击按钮,我想运行我的Java Scriptcode进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆