简体   繁体   English

如何在html按钮后面编码?

[英]how to code behind a html button?

I am trying to redirect to Search.aspx after login button is clicked. 我点击登录按钮后尝试重定向到Search.aspx。 the login button is a html5 button. 登录按钮是一个html5按钮。 I googled and they say to make it work is to add the runat="server" and önserverclick="Button1_Click". 我google了,他们说要使其工作是添加runat =“server”和önserverclick=“Button1_Click”。 After I done that, I double click on the login button on design mode. 完成后,我双击设计模式下的登录按钮。 and it generates 它会产生

function Button1_onclick() {

            }

I put the Response.Redirect("Search.aspx"); 我把Response.Redirect(“Search.aspx”); inside the function. 在功能里面。 And it still have no effect when I click the Login button. 单击“登录”按钮时,它仍然无效。

在此输入图像描述

SOURCE CODE 源代码

<%@ 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>

CODE BEHIND CODE(NOCODE) 代码背后的代码(NOCODE)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


}

try below code I hope it would help!! 尝试以下代码我希望它会有所帮助!

function Button1_onclick() 
  {
  window.location.assign("Search.aspx")
  }

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

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