views:

46

answers:

2

I have a child page LoginContent.aspx which contains a login form. If the user logs in he should be redirected to my Welcome.aspx page. But if I press the login button the page just reloads itself, nothing happens. The codebehind on this page is empty. Both LoginContent.aspx and Welcome.aspx are child forms of the same master page.

<form method="post" action="~/Welcome.aspx">
    Username: <input type="text" name="username" size="15" /><br />
    Password: <input type="password" name="passwort" size="15" /><br />
<input type="submit" value="Login"/></p>
</form>

I know I could use the asp.net login control but I want more control over things.

+1  A: 

You can't have nested form inside aspx page.

UPDATED:

Since ASP.NET webform doesn't allow us to have multiple form in one aspx page, thus in order to make it works, do the following:

  1. Remove the form tag
  2. add runat server to
  3. the input perform redirect in the server side

.

Username: <input type="text" name="username" size="15" runat=server /><br/>
Password: <input type="password" name="passwort" size="15" runat=server /><br/>
<input type="submit" value="Login" runat=server onclick="submit_onclick" /></p>

And in the code behind:

protected void submit_onclick(object sender, Event e)
{
   // do some auth stuff here
   Response.Redirect("~/welcome.aspx");
}

Hope this will answer your question.. :)

Hery
Why not? The Loginpage is rendered in the client correctly, so why shouldn't it work? AFAIK ASP.NET MVC which also uses aspx pages, builds on html instead of UserControls, how will they solve this? And what should I use instead?
codymanix
Is the sample code above asp.net mvc? If yes, then my statement isn't true. Only asp.net webform doesn't allow u to have multiple form inside aspx page.
Hery
if the code above is asp.net mvc, can you try this: remove "~" from the action url?
Hery
No it isn't MVC, just plain ASP.NET. I tried with ~/ and with ./ and without any prefix, nothing worked.
codymanix
I cannot get it to work, when I click on the button nothing happens (I changed Event into EventArgs), even if I set a breakpoint into the event handling method.
codymanix
The strange thing is that is works if I do Submit.ServerClick += new EventHandler(Submit_ServerClick), then the handler is called like it should.
codymanix
It's not strange. The reason is because you using HtmlControl. Onclick refers client side click, while serverclick refers to serverside click.
Hery
This sounds very logical, indeed. I'll mark your answer as solution. Thank you :)
codymanix
A: 

If your <form> tag from your LoginContent.aspx nested inside your <form runat="server"> I would try moving it so it sits outside the server-side form and see if it works from there.

It might be worth tracking the HTTP requests in the Net panel of Firebug as well, just so you can see if it is actually making the HTTP POST request to /Welcome.aspx - it might help you pinpoint exactly where the problem is.

Ian Oxley
I removed the inner form tags so that only the outer ones remain (they are in the master page), but it didn't help.Thanks for the idea with Firebug. Firebug says the click on submit results in a post to Loginpage.aspx, which is correct so far, only that the event isn't get called.
codymanix
The event won't fire if you are not using controls with *runat="server"* - you should still be able to get the submitted values using Request.Form["username"] and Request.Form["password"] though :-)
Ian Oxley
I put runat="server" in my input tag but I doesn't work either..
codymanix