简体   繁体   English

按钮可以在任何地方使用,但default.aspx

[英]Button working everywhere but default.aspx

I have an ASP.NET page which has a usercontrol to log in a user. 我有一个ASP.NET页面,该页面具有用于登录用户的usercontrol。 The control appears on every page, and works everywhere except default.aspx. 该控件出现在每个页面上,并且可以在除default.aspx之外的所有位置使用。 When I click it on default.aspx, the page posts back to the same page and get a 404. Failed request tracing doesn't seem to reveal anything. 当我在default.aspx上单击它时,该页面回发到同一页面并获得404。失败的请求跟踪似乎没有揭示任何内容。 The code for the button is: 该按钮的代码是:

<asp:Button ID="Button1" runat="server" Text="Sign In" OnClick="btnLogin_Click" />

I can't see any reason this shouldn't work. 我看不到任何不起作用的原因。

I believe you may be redirecting to default.aspx on login. 我相信您可能会在登录时重定向到default.aspx。 It works everywhere else because you are redirecting to the default but breaks when you are on default.aspx itself. 它可以在其他任何地方使用,因为您将重定向到默认值,但是在使用default.aspx本身时会中断。

Check the login redirect function in debug mode and see what exactly is happening. 在调试模式下检查登录重定向功能,然后查看发生了什么。

Look for multiple forms in the rendered source, and make sure your button occurs within the form. 在渲染的源中查找多个表单,并确保您的按钮出现在表单中。 This can cause lots of problems with postback. 这可能会导致回发很多问题。

To be more clear. 更加清楚。 No nested forms. 没有嵌套表格。 Asp:buttons or anything that uses postback MUST be inside the page's singular unnested form. Asp:button或任何使用回发的东西都必须位于页面的单数形式的嵌套形式内。

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

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