English 中文(简体)
vb.net表单和jquery验证
原标题:vb.net form and jquery validation

我有一个vb.net表单按钮,在执行代码后面的函数之前,它会经过jquery验证,实际上,无论是真是假,函数都会停止,永远不会调用vb.net函数。我该如何使它继续执行代码后面?

vb.net表单(文本框和按钮)

      <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 ; 
}

         });

vb的电子邮件点击功能是

 Protected Sub emailSend_Click(ByVal sender As Object, ByVal e As EventArgs) Handles 

    emailSend.Click

   MsgBox("do any thing ") 

   End Sub
最佳回答

您尚未将emailSend_Click方法指定为按钮的事件处理程序。其次,您可以使用需要FieldValidator来实现您的验证目标。

尝试<;asp:按钮ID=“emailSend”runat=“server”文本=“send”onclick=“emailSend_Click”/>

此外,删除语句emailSend。从代码后面单击。您已经处于单击事件处理程序中。

问题回答

这是jquery版本

$( input[id$=emailSend] ).click(function(){
if($( input[id$=ToCc] ).val() ==   ){
            alert("this fienld can t be empty") ; 
            return false ; 
          } 
});

更简洁,更“jQuery”d:

$("#<%=emailSend.ClientID %>").click(function(event) { 
      if($("#<%=ToCc.ClientID %>").val() == "") { 
        alert("this field can t be empty") ;  
        event.preventDefault(); 
      }  
}); 

默认情况下,如果一切正常,它将返回true。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!