Aren Hovsepyan
Aren Hovsepyan

Reputation: 2047

Asp.Net events are not working in WebForms

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 the 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 the event is 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 a master page but putting form runat after the body, I can't use events either.

It 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.

Upvotes: 0

Views: 1036

Answers (1)

meda
meda

Reputation: 45500

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.

Upvotes: 2

Related Questions