简体   繁体   English

弹出窗口中放置的Web用户控件的按钮单击事件未触发-Asp.net Webforms

[英]Button Click Event of Web User Control that is placed inside a popup not firing - Asp.net Webforms

I have a user Control named as Login.ascx having markup 我有一个名为Login.ascx的用户控件,具有标记

 <div class="row">
        <div class="small-12 medium-6 columns">
            <p>Login Here</p>
            <label>
                Email
                        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            </label>
            <label>
                Password
                        <asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
            </label>
            <div style="width: 95%; margin: 10px auto">
                <asp:Button ID="btnLogin" CssClass="expand button" runat="server" Text="Log in" OnClick="BtnLogin_Click" />
            </div>
            <p>Not Registered Yet? <a href="../../Register.aspx">Register here &raquo</a></p>
        </div>
    </div>

C# code for user control is 用于用户控制的C#代码为

protected void BtnLogin_Click(object sender, EventArgs e)
    {
        int storeId = 1;
        using (var db = new SExpressEntities())
        {
            string password = PasswordManager.Encrypt(txtPassword.Text);
            var user =
                db.tbl_Customers.FirstOrDefault(
                    cust => cust.Email == txtEmail.Text && cust.Pwd == password && cust.StoreId == storeId);
            Response.Redirect(HttpContext.Current.Request.RawUrl, true);
        }
    }

I have put this user control on a div in my master page Main.master 我已将此用户控件放在主页Main.master的div上

 <div id="loginModel" class="reveal-modal" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog">
        <uc1:Login runat="server" ID="Login" />
        <a class="close-reveal-modal" aria-label="Close">&#215;</a>
    </div>

This is a foundation popup model which opens when I click on a button, but when i enter username and password than click on Login button, it does not fire 这是一个基础弹出模型,当我单击一个按钮时会打开,但是当我输入用户名和密码而不是单击“登录”按钮时,它不会触发

However if i drag the same user control in an independent page eg Test.aspx and run it, than the Click event of button works fine. 但是,如果我在独立页面(例如Test.aspx)中拖动相同的用户控件并运行它,则按钮的Click事件会正常工作。

If this is the same user control Login.ascx that you put in master page and on child page ie test.aspx. 如果这与您在母版页和子页上放置的用户控件Login.ascx相同,即test.aspx。 your markup says that on master page you made it a popup control. 您的标记说在母版页上将其设为弹出控件。

If you see the rendered html of both the user control portions, the user control portion on the page will appear in the form tag, but the control portion with in the master page comes outside the form tag due to making it popup, that's why the button click doesn't fire. 如果您看到两个用户控件部分都呈现了html,则页面上的用户控件部分将出现在form标记中,但是母版页中的控件部分由于弹出而出现在form标记之外,这就是为什么按钮点击不会触发。

How to solve your problem, this link might help in this regard Foundation Modal issue with asp.net 如何解决您的问题,此链接可能会在这方面对asp.net的Foundation Modal问题有所帮助

Hope it helps. 希望能帮助到你。

Just paste the below script in your master page 只需将以下脚本粘贴到母版页中

<script>
     $(document).foundation('reveal', { root_element: 'form' });  
</script>

this perfectly solved my problem as it creates the html of the popup inside form which ensures the click even fired 这完美解决了我的问题,因为它创建了表单内部弹出窗口的html,可确保甚至触发点击

How your popup component works? 您的弹出组件如何工作? ie Bootstrap popover component uses a hidden div to show popup content. 即Bootstrap popover组件使用隐藏的div来显示弹出内容。 Therefore when you put a form on it, events does not bind to popup content because content is replaced from another place.. You have try to find problem on your popup component. 因此,当您将窗体放在窗体上时,事件不会绑定到弹出内容,因为内容是从另一个位置替换的。.您试图在弹出组件上找到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM