简体   繁体   中英

Asp.Net WebForms events not working

I can`t use events of buttons in webforms

this is my master page

<body>
<form runat="server">
    <header id="header">
        <div class="container">
            <div class="row">

You

can see that I have runat="server"

this is my page with button

    <div class="slide-text">
                        <div class="contact-form bottom">
                            <h2>Sign In</h2>
                            <div class="form-group">
                                <input type="text" id="Email" runat="server" name="Mail" class="form-control" required="required" placeholder="E-Mail" />
                            </div>
                            <div class="form-group">
                                <input type="password" id="Password" runat="server" name="Password" class="form-control" required="required" placeholder="Password" />
                            </div>
                            <div class="form-group">
                                <asp:hyperlink navigateurl="SignUp" runat="server" text="Registration" />
                            </div>
                            <div class="form-group">
                                <asp:button text="Sign In" id="SignInSubmit"
 cssclass="btn btn-submit" runat="server" onclick="SignInSubmit_Click" />
                            </div>
                        </div>
                    </div>

You can see that I have all necessary things

this is code behind

protected void SignInSubmit_Click(object sender, EventArgs e)
    {
        User user = new User();
        user.Auth(Email.Value, Password.Value);
        if (user.IsAuth)
        {
            Session.Add("User", user);
            Response.Redirect("Account");
        }
    }

I used debugger but event just not working

but when I put like this

<form runat="server">
              <div class="slide-text">
                        <div class="contact-form bottom">
                            <h2>Sign In</h2>
                            <div class="form-group">
                                <input type="text" id="Email" runat="server" name="Mail" class="form-control" required="required" placeholder="E-Mail" />
                            </div>
                            <div class="form-group">
                                <input type="password" id="Password" runat="server" name="Password" class="form-control" required="required" placeholder="Password" />
                            </div>
                            <div class="form-group">
                                <asp:hyperlink navigateurl="SignUp" runat="server" text="Registration" />
                            </div>
                            <div class="form-group">
                                <asp:button text="Sign In" id="SignInSubmit" cssclass="btn btn-submit" runat="server" onclick="SignInSubmit_Click" />
                            </div>
                        </div>
                    </div>
</form>

it is working (of course I am deleting form in master page).

I can`t understand why it is not working

NOTE I don`t get exceptions just event not firing

Also

when I am not using master page but puting form runat after body I can`t use events too

Its works only like this

    <form runat="server">
    <div class="slide-text">
                        <div class="contact-form bottom">
                            <h2>Sign In</h2>
                            <div class="form-group">
                                <input type="text" id="Email" runat="server" name="Mail" class="form-control" required="required" placeholder="E-Mail" />
                            </div>
                            <div class="form-group">
                                <input type="password" id="Password" runat="server" name="Password" class="form-control" required="required" placeholder="Password" />
                            </div>
                            <div class="form-group">
                                <asp:hyperlink navigateurl="SignUp" runat="server" text="Registration" />
                            </div>
                            <div class="form-group">
                                <asp:button text="Sign In" id="SignInSubmit"
 cssclass="btn btn-submit" runat="server" onclick="SignInSubmit_Click" />
                            </div>
                        </div>
                    </div>
</form>

I hope you can help me

Thanks in advance

When you create the webform, make sure you check the checkbox that says to use the master page which contains a form already.

On your Webform.aspx no need for another form, it is already provided by the master page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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