Reputation: 25080
i have a vb.net form button that go through a jquery validation before excude a function in the code behind , actually in either ways if the validation is true or false the function stopped and never call the vb.net function how can i make the it proceed to the code behind ?
vb.net form (textbox and button )
<asp:TextBox ID="ToCc" runat="server"></asp:TextBox>
<asp:Button ID="emailSend" runat="server" Text="send" />
jquery :
$("#<%=emailSend.ClientID %>").click(function(){
if($("#<%=ToCc.ClientID %>").val() == ""){
alert("this fienld can't be empty") ;
return false ;
} else{
return true ;
}
});
the email click vb function is
Protected Sub emailSend_Click(ByVal sender As Object, ByVal e As EventArgs) Handles
emailSend.Click
MsgBox("do any thing ")
End Sub
Upvotes: 0
Views: 1337
Reputation: 12037
More concise and a little more "jQuery"'d:
$("#<%=emailSend.ClientID %>").click(function(event) {
if($("#<%=ToCc.ClientID %>").val() == "") {
alert("this field can't be empty") ;
event.preventDefault();
}
});
By default it'll return true if everything is OK.
Upvotes: 0
Reputation: 12561
You haven't assigned your emailSend_Click method as the event handler for the button. Secondly, you can use the RequiredFieldValidator to accomplish your validation goals.
Try <asp:Button ID="emailSend" runat="server" Text="send" onclick="emailSend_Click" />
Additionally, remove the statement emailSend.Click
from your code behind. You are already in the click event handler.
Upvotes: 1
Reputation: 3169
this is jquery version
$('input[id$=emailSend]').click(function(){
if($('input[id$=ToCc]').val() == ''){
alert("this fienld can't be empty") ;
return false ;
}
});
Upvotes: 0