从客户端javascript运行服务器端代码 [英] Running serverside code form client side javascript

查看:93
本文介绍了从客户端javascript运行服务器端代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在按钮上单击客户端执行文本框验证我想在验证后执行服务器端代码。如果验证失败,则控制仍在客户端。我怎么能这样做?

on a button click client side validation of text boxes is performed i want to execute server side code after validation. if validation fails the control remains on client side. how can i do this?

推荐答案

如果你正在使用asp按钮,那么需要在事件上调用javaScript OnClientClick [ ^ ]。



然后在那个调用javaScript函数来验证如下...

If you are using asp button, then the javaScript need to be called on the event OnClientClick[^].

Then on that call javaScript function to validate like below...
<asp:Button ID="Button1"

       text="Open Web site"

       onclientclick="return Validate()"

       runat="server" onclick="Button1_Click" />





现在javaScript函数将验证并返回适当的布尔值,如下所示...



Now the javaScript function will validate and return appropriate boolean value like below...

function Validate(){
    if validated
        return true;
    else
        return false;
}





因此,当它未经过验证时,它将返回false并且服务端事件 Button1_Click 不会触发,如果返回true,则服务器端事件将被触发。



So, when it is not validated it will return false and the service side event Button1_Click will not fire and if it returns true, then the server side event will get fired.


这篇关于从客户端javascript运行服务器端代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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