在aspx页面中有两个按钮。第二个按钮是弹出窗口,无效 [英] having two buttons in aspx page. second button is in popup which is not working

查看:69
本文介绍了在aspx页面中有两个按钮。第二个按钮是弹出窗口,无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是aspx页面

this is aspx page

<div class="detail_label">
                <asp:Button ID="btn_purchase" runat="server" Text="Add To Cart" OnClick="btn_purchase_Click" /></div>
          <div class="parentdiasble" runat="server">
            </div>
                <div id="popupdiv" runat="server" style="display: none" >

                            <table>
                                <tr>
                                    <td><span class="txt">Username: </span><span class="redstar">*</span></td>
                                    <td>
                                        <asp:TextBox ID="txtUserName" runat="server" placeholder=" UserName"

                                            Width="186px"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvUserName" runat="server"

                                            ErrorMessage="Please enter  User Name" ControlToValidate="txtUserName" ValidationGroup="Login"

                                            Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td><span class="txt">Password: <span class="redstar">*</span> &nbsp;&nbsp;</span></td>
                                    <td>
                                        <asp:TextBox ID="txtPwd" runat="server" TextMode="Password" placeholder=" Password" Width="186px"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"

                                            ControlToValidate="txtPwd" Display="Dynamic" ValidationGroup="Login"

                                            ErrorMessage="Please enter Password" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td></td>
                                    <td>
                                        <asp:Button ID="btnSubmit" ValidationGroup="Login" runat="server" Text="Login" OnClick="btnSubmit_Click"/>
                                        <asp:Button ID="btnclose"  runat="server" Text="Cancel" CausesValidation="false" style="height: 26px" /></td>
                                </tr>

                                <tr>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                </tr>

                            </table>
                      </div>



这是针对c#代码的背后


this is for c# code behind

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("popupid_sp", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@name", txtUserName.Text);
        Class2.userid = Convert.ToInt32(cmd.ExecuteScalar());
        HttpCookie cookie = new HttpCookie("useridCookie");
        cookie["idCookie"] = Convert.ToString(Class2.userid);
        Response.Cookies.Add(cookie);
        Context.Server.Transfer("~/webpages/detail_page.aspx");
        
       
    }


  
    protected void btn_purchase_Click(object sender, EventArgs e)
    {
        if (Request.Cookies["idCookie"] == null)
        {
            ScriptManager.RegisterStartupScript(Page, typeof(Page), "Popup", "popuplogin()", true);
        }
        else
        {
            Context.Server.Transfer("~/webpages/detail_page.aspx");

        }
this is for javascript
function popuplogin()
       {

              $("#popupdiv").dialog({
               title: "login",
               width: 430,
               height: 250,
               modal: true,
               buttons: {
                   //close: function () {
                   //    __dopostback('btnsubmit', '');
                   //}
               }

           });

       }





按钮位于popupdiv内部并未触发

善意回复



button which is in inside of the popupdiv is not firing
kindly response

推荐答案

#popupdiv)。dialog({
title: login
width: 430
height: 250
modal: true
按钮:{
// close :function(){
// __dopostback('btnsubmit','');
// }
}

});

}
("#popupdiv").dialog({ title: "login", width: 430, height: 250, modal: true, buttons: { //close: function () { // __dopostback('btnsubmit', ''); //} } }); }





按钮位于popupdiv内部并未触发

友好回应



button which is in inside of the popupdiv is not firing
kindly response


您好shanmugaprabu198512,



我认为弹出窗口中的第二个按钮只有在您的验证组登录成功验证时才会触发。

如果您的验证没有成功,那么您的按钮将不会触发Click事件。



要检查是否只删除了ValidationGroup =Login并将CausesValidation =false添加到Button并单击。它现在将触发其点击事件。



所以问题在于验证如果passess按钮将完成它们的工作,否则它的事件被验证规则阻止。
Hi shanmugaprabu198512,

I think Your Second Button within popup will only fire if your validation Group Login validates successfully.
If your validation not succeeds then your button will not fire Click event.

To Check that just remove your ValidationGroup="Login" and add CausesValidation="false" to Button and click . It will fire its click event now.

So the problem is with validation if it passess button will do their job otherwise its event prevented by validation rule.


这篇关于在aspx页面中有两个按钮。第二个按钮是弹出窗口,无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆