[英]ASP.NET C# <asp:Button type=“button”> but still acting like <asp:Button type=“submit”>
<asp:Button runat="server" id="LoginBtn" type="Button" Text="Login" OnClientClick="document.getElementById('jsLogin').style.display='inline-grid'" />
As the title states, the above line of code is what is present in my Master.master page. 如标题所示,上面的代码行是我的Master.master页面中显示的内容。
But when I run the debugger (visual studio 2017), chrome and the application run the button with a postback, and when I examine the element, it's still showing 但是当我运行调试器(Visual Studio 2017)时,chrome和应用程序运行带有回发的按钮,当我检查元素时,它仍然显示
<input type="submit" name="ctl00$LoginBtn" value="Login" onclick="document.getElementById('jsLogin').style.display='inline-grid';" id="LoginBtn">
I have zero clue what to do. 我零线索该怎么办。
UPDATE 7/19/2018 (20 minutes later) 更新7/19/2018(20分钟后)
reverted to an older source control: 恢复为较旧的源代码管理:
the only change was near the top of the master.master: 唯一的变化是在master.master的顶部附近:
<html lang="en-us">
<form runat="server">
<head runat="server">
<asp:scriptmanager runat="server"></asp:scriptmanager>
instead of 代替
<html lang="en-us">
<head runat="server">
<form runat="server">
<asp:scriptmanager runat="server"></asp:scriptmanager>
and on the Default.aspx page this line: 在Default.aspx页面上,此行:
<%@ MasterType VirtualPath="~/Master.master" %>
is not commented out. 没有被注释掉。
Literally nothing else changed Oo Someone who knows more about ASP.Net than me please clue me in. 从字面上看,其他所有内容都没有改变。Oo比我更了解ASP.Net的人,请提示我。
Update 7/20/2018 - 18:39 gmt 更新7/20/2018-18:39 gmt
Reproduced the root cause. 重现了根本原因。
<asp:textbox>
was set to required . 设置为必填 。 I removed the required and created a custom javascript function. 我删除了必填项,并创建了一个自定义javascript函数。 Apparently there is a problem with FormsAuthentication.Signout() when you try to clear authentication on hidden forms that have required set. 当您尝试清除具有必需集合的隐藏表单上的身份验证时,显然FormsAuthentication.Signout()存在问题。
<script>
function validation() {
var username = document.getElementById('uNameLogin').value;
var password = document.getElementById('uPasswordLogin').value;
if (username == null || password == null || username == "" || password == "")
{
document.getElementById('uNameLogin').value = "User Name & Password Required!";
return false;
}
}
</script>
after adding that, to prevent the post back I followed the suggestion of adding return false to the OnClientClick javascript: 添加完之后,为防止回发,我遵循将return false添加到OnClientClick javascript的建议:
OnClientClick="javascript:document.getElementById('jsLogin').style.display='inline-grid'; return false;"
and it resolved the problem of the Login button causing postback. 并且解决了导致回发的“登录”按钮的问题。
尝试跟随
<asp:Button runat="server" id="LoginBtn" type="Button" Text="Login" OnClientClick="javascript:document.getElementById('jsLogin').style.display='inline-grid'; return false;" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.