当前位置:网站首页>ASP.Net利用代码点击相应按钮来关闭当前的页面(亲测有效)
ASP.Net利用代码点击相应按钮来关闭当前的页面(亲测有效)
2022-08-10 05:35:00 【三和尚】
1、请创建一个简单的网站。要求:
WebForm1.aspx页面为用户登陆页面,登陆成功的判断条件为:可登陆成功的用户名为:computer Application15,密码为:2015Comp。清空按钮功能用于将用户名和密码清空,关闭按钮用于关闭该网页。请编写出该网站的前端界面和后台代码(用C#语言进行编写)。
aspx代码(前端界面的代码):
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style>
table,td{
border:solid 1px #00ffff;
}
</style>
</head>
<body>
<form id="form1" runat="server" >
<div>
<table>
<tr>
<td>用户名</td>
<td colspan="3">
<asp:TextBox id="text" runat="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td>密 码</td>
<td colspan="3">
<asp:TextBox id="password" runat="server" ></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td colspan="3">
<asp:Button ID="Button1" runat="server" Text="登录" OnClick="Button1_Click1" />
<asp:Button ID="Button2" runat="server" Text="清空" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="关闭" OnClick="Button3_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
下面重点来了,就是控制页面的登录、清空、关闭这些点击按钮事件的CS代码(后台代码):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//点击关闭按钮的时候关闭当前页面
//服务器数据返回时,生成页面时,关闭掉生成的页面
this.Button3.Attributes.Add("onclick", "window.close();");
}
protected void Button1_Click1(object sender, EventArgs e)
{
string Name = this.text.Text;
string password = this.password.Text;
if (Name == "computer Application15" && password == "2015Comp")
{
Response.Write("<script>alert('登录成功!!')</script>");
}
else
{
//Response.Write表示服务器端向页面写数据
Response.Write("<script>alert('用户名或密码输入错误')</script>");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
this.text.Text = "";
this.password.Text = "";
}
//同时数据提交到后台
protected void Button3_Click(object sender, EventArgs e)
{
//onclick是通过javascript执行的,是页面端程序,此代码不会提交到服务器端
//所以服务器端返回信息时,此代码销毁了,返回时不会提交到客户端,所以无法关闭页面。
//this.btn3.Attributes.Add("onclick", "window.close();");//两者是同时触发的,
}
}
点击保存,然后就是运行该代码,点击相应的按钮就会触发相应的点击事件!!!
边栏推荐
- Common class BigDecimal
- 常用模块封装-csv文件操作封装
- 样条曲线(下)之插值问题(贝塞尔曲线、B样条和一般样条曲线插值)
- GUI_AWT
- Convolutional Neural Network (CNN) for Clothing Image Classification
- 解决错误 Could not find method leftShift() for arguments
- LeetCode 100. The same tree (simple)
- pytorch-05.用pytorch实现线性回归
- LeetCode refers to offer 10-I. Fibonacci sequence (simple)
- LeetCode 1351.统计有序矩阵中的负数(简单)
猜你喜欢
随机推荐
LeetCode 100. The same tree (simple)
LeetCode 1720. Decoding XORed Arrays (Simple)
51单片机BH1750智能补光灯台灯光强光照恒流源LED控制系统
Likou - Number of Provinces
LeetCode 292.Nim 游戏(简单)
自定义View的流程总结学习
样条曲线(下)之插值问题(贝塞尔曲线、B样条和一般样条曲线插值)
卷积神经网络(CNN)实现服装图像分类
过大数组导致爆栈的解决方法记录(堆栈)
堆的原理与实现以及排序
棋类游戏-五子棋小游戏
(Flutter报错)Cannot run with sound null safety, because the following dependencies
pytorch-07.处理多维特征的输入
解决错误 Could not find method leftShift() for arguments
PyTorch的安装与基础知识
离散数学的学习记录
学生管理系统以及其简单功能的实现
pytorch-09. Multi-classification problem
Gradle学习 (一) 入门
LeetCode 1351.统计有序矩阵中的负数(简单)









