C# 如何在html按钮后面编写代码?
单击登录按钮后,我试图重定向到Search.aspx。登录按钮是html5按钮。我在谷歌上搜索过,他们说要让它工作起来,需要添加runat=“server”和önserverclick=“Button1\u Click”。完成后,我双击设计模式上的登录按钮。它产生了C# 如何在html按钮后面编写代码?,c#,html,button,code-behind,C#,Html,Button,Code Behind,单击登录按钮后,我试图重定向到Search.aspx。登录按钮是html5按钮。我在谷歌上搜索过,他们说要让它工作起来,需要添加runat=“server”和önserverclick=“Button1\u Click”。完成后,我双击设计模式上的登录按钮。它产生了 function Button1_onclick() { } 我把Response.Redirect(“Search.aspx”);函数内部。当我点击登录按钮时,它仍然没有效果 源代码 <%@ P
function Button1_onclick() {
}
我把Response.Redirect(“Search.aspx”);函数内部。当我点击登录按钮时,它仍然没有效果
源代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
</style>
<link rel="stylesheet" type="text/css" href="stylesheets/loginstyle.css" />
<script language="javascript" type="text/javascript">
// <![CDATA[
function Button1_onclick() {
Response.Redirect("Search.aspx");
}
// ]]>
</script>
</head>
<body>
<div id="wrapper">
<form name="login-form" class="login-form" action="" method="post">
<div class="header">
<h1>Login Form</h1>
<span>Fill out the form below to login to my super awesome imaginary control panel.</span>
</div>
<div class="content">
<input name="username" type="text" class="input username" placeholder="Username" />
<div class="user-icon"></div>
<input name="password" type="password" class="input password" placeholder="Password" />
<div class="pass-icon"></div>
</div>
<div class="footer">
<input type="button" name="submit" value="Login" class="button" runat="server" id="Button1" önserverclick="Button1_Click" onclick="return Button1_onclick()" />
</div>
</form>
</div>
<div class="gradient"></div>
</body>
</html>
尝试下面的代码,我希望它会有所帮助
function Button1_onclick()
{
window.location.assign("Search.aspx")
}
这与HTML5有什么关系?代码背后是ASP.NET服务器端代码。另外,您的DOCTYPE是XHTML 1.0,而不是HTML5erm。也许我应该将它改为,如何在html按钮后面编码@猛禽
önserverclick
<代码>ö?呃,谢谢你,它成功了。但我要对登录按钮进行编码。输入正确的用户名和密码后。单击登录按钮,它将重定向到Search.aspx。我会遇到什么问题吗?是否只用于重定向,那么我只需要window.location.assign代码@Neelyou可以使用if-else条件,如用户输入正确的要求,然后重定向到此页面,否则重定向到另一页面@Jordjmax我创建了另一个关于我使用硬代码登录问题的线程。你有空的时候帮我?谢谢@Neelmust我必须在源代码中键入我的代码吗?是否无法在aspx.cs文件中生成代码?在源代码中编写代码似乎更难。现在我想将会话添加到我的登录代码中,它可以;t work@Neelyou可以像这样用javascript创建会话:-会话[“controlID”]=“这是我的会话”@乔德马克斯
function Button1_onclick()
{
window.location.assign("Search.aspx")
}