【问题标题】:Asp button doesn't trigger functionasp按钮不触发功能
【发布时间】:2021-02-27 16:16:14
【问题描述】:

我的项目有一个注册页面,这部分对我不起作用:

<input type="email" id="email" title="invalid email!" runat="server" placeholder="email" />
<input type="text" id="username" runat="server" placeholder="username " />
<input type="password" title="Password needs to contain at least one big letter and digits" pattern="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$" id="password" runat="server" placeholder="password" />
<input type="text" id="phone" title="invalid phone!" pattern="^\s*(?:\+?(\d{1,3}))?([-. (]*(\d{3})[-. )]*)?((\d{3})[-. ]*(\d{2,4})(?:[-.x ]*(\d+))?)\s*$" runat="server" placeholder="phone number" />
<asp:Button runat="server" ID="signUpBotton" OnClick="signUp" Text="sign up"/> 

我在后面的代码中有注册部分,但asp:button 甚至没有触发该功能并且它不起作用。

【问题讨论】:

    标签: c# html asp.net web


    【解决方案1】:

    你必须像方法一样调用你的函数:“signUp()”而不仅仅是“signUp”

    【讨论】:

    • 此函数获取对象发送者,EventArgs e 参数
    【解决方案2】:

    可能有多种原因,我们无法继续猜测所有原因,这就是为什么您应该尽可能多地描述您的问题。所以,我在这里的感觉是,您有一个form,它在单击该按钮时被提交,这就是原始事件被忽略而不被触发的原因。您可能想要做的是,将按钮的提交行为设置为 false。在您的按钮中添加此属性:

    UseSubmitBehavior="false" 
    

    所以,按钮标记是这样的:

    <asp:Button runat="server" ID="signUpBotton" OnClick="signUp" Text="sign up" UseSubmitBehavior="false" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多