首页 > 代码库 > 普通按钮的另一种提交方式(调用后台事件)
普通按钮的另一种提交方式(调用后台事件)
后台:
protected void ibtnRegedit_Click(object sender, ImageClickEventArgs e)
{
if (!Page.IsValid || !CheckVCode())
return;
.......
}
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
<script type="text/javascript"> var Ok = true;//false异步没回来不让提交,true异步没回来可以提交 function btnClick() { var val = $("#<%=txtUName.ClientID %>").val(); if (val != "") { $.post("/ashx/CheckUser.ashx", { "loginid": val }, function () { if (arguments[0] == "1") { $("#iE").attr("src", "/Images/dui.ico").show(); Ok = true; Page_ClientValidate(null);//调用全局的方法 if (Page_IsValid) { __doPostBack(‘ctl00$ContentPlaceHolder1$ibtnRegedit‘, ‘‘);//由LinkButton产生参数1:Name非ID } } else { $("#iE").attr("src", "/Images/cha.ico").show(); Ok = false; } } , "text"); } }; </script>
<asp:ImageButton ID="ibtnRegedit" runat="server" ImageUrl="~/Images/az-finish.gif" OnClick="ibtnRegedit_Click" /><asp:LinkButton ID="LinkButton1" runat="server" Visible="False"></asp:LinkButton><input type="button" name="btnSub" onclick="btnClick();" id="" value=http://www.mamicode.com/"完 成" style="height: 20px; width: 50px; border-style:solid none ;" />
网页源码:
<script type="text/javascript"> //<![CDATA[ var theForm = document.forms[‘aspnetForm‘]; if (!theForm) { theForm = document.aspnetForm; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script>
网页源码:
<input type="image" name="ctl00$ContentPlaceHolder1$ibtnRegedit" id="ctl00_ContentPlaceHolder1_ibtnRegedit" src=http://www.mamicode.com/"../../Images/az-finish.gif" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$ibtnRegedit", "", true, "", "", false, false))" style="border-width:0px;" /><input type="button" name="btnSub" onclick="btnClick();" id="" value=http://www.mamicode.com/"完 成" style="height: 20px; width: 50px; border-style:solid none ;" />
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。