首页 > 代码库 > 普通按钮的另一种提交方式(调用后台事件)

普通按钮的另一种提交方式(调用后台事件)

后台:

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(&quot;ctl00$ContentPlaceHolder1$ibtnRegedit&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, 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 ;" />