且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

停止服务器端执行

更新时间:2023-11-27 22:00:16


您的Java脚本函数在执行时返回true.这样您的页面就会被发回.修改您的Java脚本函数,使其在出现警报消息时将返回false.

function validate_form ( )
        {
 
            var  valid = true;
            if ( document.getElementById("ctl00_ContentPlaceHolder1_txtAssetDescription").value == "" )
            {
                alert ("Please Enter Asset Description");
                txtAssetDescription.focus();
                return false;
            }
retutn valid; 
}



希望这会有所帮助:)

谢谢
Vinod


IN ONclientClick使用return btnsaveclick()...如图所示

< asp:Button ID = "  runat = "  Text = " 保存" Width =   75px"
                       OnClientClick = " 
                      onclick = " /> 





在ur函数中,您必须将其返回为false

函数validate_form()
        {


返回 ;
} 


尝试用以下代码替换您的代码


函数validate_form()
        {

             var  valid =  true ;
            如果(document.getElementById(" ). == "  )
            {
                有效=  false ;
                警报(" );
                txtAssetDescription.focus();
                返回有效;
            }
返回有效;
} 




< asp:Button ID = "  runat = "  Text = " 保存" Width =   75px"
                       OnClientClick = " 
                      onclick = " /> 


>

Hi All,
I have done Client Side validation through Java Script. Validation works Fine . but after validation Server code also get exceuted. i want to stop the server code.

Ex:

function validate_form ( )
        {

            var  valid = true;
            if ( document.getElementById("ctl00_ContentPlaceHolder1_txtAssetDescription").value == "" )
            {
                alert ("Please Enter Asset Description");
                txtAssetDescription.focus();
                return valid ;
            }
retutn valid; 
}





Server Code:

<asp:Button ID="btnSave" runat="server" Text="Save" Width="75px"
                       OnClientClick="validate_form()"
                      onclick="btnSave_Click"/>





Now Validation Works but the code written in btnSave also get executed, how to stop that?


Regards,
Pal

Hi
your java-script function returns true when its get executed. so your page will get post back. modify you java-script function in such a way that it will returns false when there is alert message.

function validate_form ( )
        {
 
            var  valid = true;
            if ( document.getElementById("ctl00_ContentPlaceHolder1_txtAssetDescription").value == "" )
            {
                alert ("Please Enter Asset Description");
                txtAssetDescription.focus();
                return false;
            }
retutn valid; 
}



Hope this will help :)

Thanks
Vinod


IN ONclientClick use return btnsaveclick ()... as shown

<asp:Button ID="btnSave" runat="server" Text="Save" Width="75px"
                       OnClientClick="return validate_form()"
                      onclick="btnSave_Click"/>





in ur function u have to return it as false

function validate_form ( )
        {


return false;
}


try replace your code with these


function validate_form ( )
        {

            var  valid = true;
            if ( document.getElementById("ctl00_ContentPlaceHolder1_txtAssetDescription").value == "" )
            {
                valid = false;
                alert ("Please Enter Asset Description");
                txtAssetDescription.focus();
                return valid ;
            }
return valid;
}




<asp:Button ID="btnSave" runat="server" Text="Save" Width="75px"
                       OnClientClick="javascript:return validate_form();"
                      onclick="btnSave_Click"/>