我有一个按钮单击事件,我添加了javascript确认框(是/否)。我希望当用户单击yes时,该方法将运行。示例如下:
Asp.Net C#后端:
Response.Write("<script>var confirmdelete=confirm('No chronological event found.Do you want to continue ?');if (confirmdelete) {('<%=ASPxButton_Approve%>').valueof()}</script>");ASPxButton_Approve =是我要触发的按钮
之后,它将显示yes no确认框。我希望当用户单击下面的yes时,方法将运行:
approve();发布于 2016-10-12 14:20:05
在按钮客户端单击只有你可以写
例如:
<asp:Button ID="btnSubmit" class="btn btn-success waves-effect waves-light" TabIndex="5" ValidationGroup="validate" formnovalidate="formnovalidate" runat="server" Text="Submit" OnClientClick="if (Page_ClientValidate()){ return confirm('Do you want to add task? Click OK to proceed.')}" OnClick="btnSubmit_Click" />发布于 2016-10-12 14:31:36
你可以使用OnClientClick属性,在你的前端文件中放一个这样的按钮:
<asp:LinkButton ID="lnkDelete" runat="server" CausesValidation="false"
CommandName="Delete" CommandArgument="optionalParameterLikeAKey"
OnCommand="lnkDelete_Command" OnClientClick="return confirm('No
chronological event found.Do you want to continue ?');" Text="Delete">在后面的代码中捕获动作命令"Delete":
void lnkDelete_Command(Object sender, CommandEventArgs e) {
//Code to delete -> e.CommandArgument;
}或者,您可以使用:
<a href="YourPage.aspx?ID=<%#DataBinder.Eval(Container.DataItem, "ID")%>&action=delete" onclick="return confirm('No
chronological event found.Do you want to continue ?');">Delete</a>我希望它能帮上忙。
发布于 2016-10-12 14:37:16
我建议您创建一个javascript函数,并在ASP.NET中使用CustomValidator,这是一种处理客户端代码的强大功能。
用于在客户端上创建自定义验证逻辑的
在ECMAScript (JavaScript,JScript)中创建验证函数:下面的代码示例演示自定义客户端验证。该页的摘录显示了由CustomValidator控件引用的TextBox控件。验证控件调用名为validateLength的客户端脚本函数,以确保用户在TextBox控件中至少输入了八个字符。
一个典型的例子是:
<script type="text/javascript">
function validateLength(oSrc, args){
args.IsValid = (args.Value.length >= 8);
}
</script>C#代码:
<asp:Textbox id="text1" runat="server" text=""></asp:Textbox>
<asp:CustomValidator id="CustomValidator2" runat="server"
ControlToValidate = "text1"
ErrorMessage = "You must enter at least 8 characters!"
ClientValidationFunction="validateLength" >
</asp:CustomValidator>有关更多信息,请访问here。
https://stackoverflow.com/questions/39991593
复制相似问题