开发者

An Page reload problem in ASP .net because of client side validaton

I have an aspx page where I have used jquery validator in a different .js file. my code for this file is

function checkRequiredInputs(){

$("#frmSaleSubmissionInfo").validate({  
    rules:{
        txtFName:{required: true},
        txtLName:{required: true},
        txtAddress:{required: true},
        txtPhone:{required: true}
    },
    messages:{
        txtFName:"Enter Name",
        txtLName:"Enter Name",
        txtAddress:"Enter Address",
        txtPhone:"Enter Phone Number"
    }
});

$("#txtPhone").keydown(function(event) {
    // Allow only backspace,delete,comma(,),left arrow,right arraow and Tab
    if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 188 
        || event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 9){
        // let it happen, don't do anything
    }
    else {
        // Ensure that it is a number and stop the keypress
        if ((event.keyCode < 48 || event.keyCode > 57) && (event.keyCode <96 ||event.keyCode > 105) ) {
            event.preventDefault(); 
        }   
    }
});

} 

and the validation code is implemented in the aspx

<script type="text/javascript">   
    $(document).ready(function(){
        checkRequiredInputs();
}); 

 </script>

I have a close button and it's like

<asp:ImageButton ID="btnClose" runat="server" ImageUrl="~/ButtonImages/Button_Close_Normal.png"
                    Height="16px" onclick="btnClose_Click" />

and its click event is protected void btnClose_Click(object sender, ImageClickE开发者_开发问答ventArgs e) { Response.Redirect("anotherPage.aspx", false); }

Now my problem is that whenever I click close button, if the validation fails, i.e. if any of the required field remains empty, its not letting to the go that another page. But if validation does not occur, then, The close button takes me to that another page. My obejct is to make that close button work regardless of any client side validation? What will I do? please help me, thank you in advance


If all you're doing when you click btnClose is: Response.Redirect("anotherPage.aspx", false); then why bother with a server side control at all? I would replace btnClose with:

<a href="/anotherPage.aspx"><img src="~/ButtonImages/Button_Close_Normal.png" /></a>

This will work regardless

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜