C#实现简单网页

C#实现简单网页⑴创建ASP.NET网站新建MyWebSite网站,添加一个WebForm1网页,其中包含一个文本框TextBox1一个按钮Button1(计算)和一个标签Label1(””)。在文本框中输入一个数,当点击“计算”按钮时,在标签中显示此数的平方根。WebForm1.aspx文件内容如下:<%@PageLanguage=”C#”AutoEventWireup=”true…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

⑴ 创建ASP.NET网站

新建MyWebSite网站,添加一个WebForm1网页,其中包含一个文本框TextBox1一个按钮Button1(计算)和一个标签Label1(””)。在文本框中输入一个数,当点击“计算”按钮时,在标签中显示此数的平方根。

WebForm1.aspx文件内容如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="shiyan1.WebForm1" %>
<!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">
        .TextBox1 {
            width: 20px;
            height: 5px;
            right: 50%;
            left: 50%;
            margin-top: 20px;
            margin-right: 400px;
        }
        .Button1
        {
            width: 10px;
            height: 4px;
            right: 500px;
            left: 500px;
        }
    </style>
</head>
<body class="TextBox1">
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
    </div>
    <p>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="计算" 
            Width="73px" Height="29px" />
    </p>
    </form>
</body>
</html>

WebForm1.aspx.cs文件如下:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace shiyan1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Button1_Click(object sender, EventArgs e)
        {
            double num = Convert.ToDouble(TextBox1.Text);
            Label1.Text = Math.Sqrt(num).ToString();
        } 
    }
}

实现数据的前后台调用

实现样式如下:

C#实现简单网页

 

⑵ DIV/CSS布局

使用HTML标签设计如下所示表单

C#实现简单网页

 

Webform1.aspx文件:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="shiyan112.WebForm1" %>
<!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>实验1</title>
      <style type="text/css">
        *{
            left: 50px;
            padding: 0px;
            margin: 0px;
            border: 1px solid #FFFFFF;
        }
        #div0
        {
            left: 50px;
            width: 600px;
            margin: auto;
            border-style: solid;
            border-width: 1px;
        }
        fieldset
        {
            border: 1px solid #000000;
            margin: -15px 0px 0px 0px;
            width: 500px;
            height: 362px;
            padding-left: 150px;
        }
        label
        {
            font-weight: bold;
            font-size: 12px;
            height: 19px;
            float: none;
            margin-left: 0px;
            text-align: right;
        }
        #name01, #pass01, #pass02, #zjhm, #dh
        {
            border: 1px solid #3ca1af;
            height: 19px;
            width: 130px;
        }
        .juli
        {
            line-height: 21px;
            width: 130px;
            float: left;
            display: block;
            padding-right: 0px;
            height: 19px;
            clip: rect(auto, auto, auto, 0px);
        }
        #button
        {
            margin: 0px 0px 0px 150px;
            font-size: 12px;
            font-family: 黑体;
            font-weight: bold;
            padding: 0px;
            height: 16px;
            width: 48px;
            float: none;
        }
        #zjzl
        {
            width: 140px;
            height: 22px;
        }
        a
        {
            font-size: 12px;
        }
        .c1
        {
            border: 1px solid #00FFFF;
            padding: 0px;
            width: 80px;
            height: 20px;
            margin-left: 424px;
            margin-top: 50px;
            font-size: 14px;
            background-color: #FFFFFF;
        }
    </style>
</head>
<body>
  <form id="form1" runat="server">
    &nbsp;<input  type="button" class="c1" value="用户注册" onclick="return button_onclick()" />
    <div id="div0">
        <fieldset >           
            <br />
            <label for="name01" class="juli">用户名:</label>
            <input type="text" id="name01" />
            <br />
            <br />
            <label for="pass01" class="juli">密码:</label>
            <input type="password" id="pass01" />
            <br />
            <br />
            <label for="pass02" class="juli"> 确认密码:</label>
            <input type="password" id="pass02" />
            <br />
            <br />
            <label for="zjzl" class="juli">密码保护问题:</label>
                 <select id="zjzl" onclick="return zjzl_onclick()">
                    <option id="zjzl1">请选择密码提示问题</option>
                    <option id="zjzl2">问题一</option>
                 </select>
            <br />
            <br />
            <label for="zjhm" class="juli">密码保护问题的答案:</label>
            <input type="text" id="zjhm" />
            <br />
            <br />
            <label class="juli">性别:</label>
            <input type="radio" name="dx" value="单选" id="dx_0" />
            <label for="dx_0">男</label>
            <input type="radio" name="dx" value="单选" id="dx_1" />       
            <label for="dx_1">女</label>
            <br />
            <br />
            <label class="juli"> 同意服务条款:</label>
            <input type="checkbox" name="vehicle" value="Bike" /><a href="#">查看服务条款?</a>
            <br />
            <br />
            <input type="button" id="button" value="提 交"  /></fieldset>    
    </div>
    </form>
</body>
</html>

小Tips:

如何给前端页面添加样式:

点击设计 — > 选择格式  — 》新建样式

C#实现简单网页

(3)简单表单设计

实现如下界面;

C#实现简单网页

 

ThisPage.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div id="div0">
       <fieldset>
           <legend>填写信息</legend>
           <br />
           <label for="name01">用户名:</label>
           <input type="text" id="name01" />
           <br /><br />
           <label for="pass01">密码:</label>
           <input type="password" id="pass01" />
           <br /><br />
           <label for="pass02">确认密码:</label>
           <input type="password" id="pass02" />
           <br /><br />
           <label for="sfz">证件种类:</label>
           <select id="sfz">
              <option id="sfz1">身份证</option>
              <option id="sfz2">学生证</option>
           </select>
           <label for="number">证件号码:</label>
           <input type="text" id="number" />
           <br /><br />
           <label for="tel">联系方式:</label>
           <input type="radio" name="dx" value="单选" id="dx_0" />
           <label for="dx_0">手机</label>
           <input type="radio" name="dx" value="单选" id="dx_1" />
           <label for="dx_1">座机</label>
           <input type="text" id="tel" />
           <br /><br />
           <input type="button" id="button" value="确定" />
       </fieldset>

    </div>
    </form>
</body>
</html>

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/182461.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • pycharm怎么修改快捷键_vb中运行程序的快捷键是什么

    pycharm怎么修改快捷键_vb中运行程序的快捷键是什么在Pycharm中默认运行的快捷键是Ctrl+Shift+F10。如何修改Pycharm运行的快捷键?步骤一:在File中找到Settings.步骤二:找到Keymap,并在搜索框中搜索run,找到对应的【Run】.步骤三:右键点击Run,选择【AddKeyboardShortcut】.步骤四:在此处填入想设置的快捷键即可.最后点击应用和OK即可设置完毕!成功!!!…

    2022年8月25日
    4
  • 要想成功先脱去幼稚

    要想成功先脱去幼稚记者问:“人要活得明白通透需要时间吗?”郭德纲答:“不需要时间,需要经历。一个人六十了,从小没挨过打,没人说过什么难听话。走大街上,别人瞪了一眼,咔,死了;一个人从小每天挨十个嘴巴,天天挨骂,长大了铁罗汉,抗压能力高。”经历过大风大浪真的可以帮助我们变得成熟稳重,那么问题来了,我们每天经历不了那么多的风浪,怎么办?这个时候,我认为应该先提高自己的思想。人不成熟的五大特征:人不成熟的第一…

    2022年6月2日
    31
  • vue自定义组件封装_vue组件的双向绑定实现

    vue自定义组件封装_vue组件的双向绑定实现vue组件封装,vueelementui组件封装,vue图片上传,elementui图片上传

    2022年9月23日
    0
  • JMH入门

    JMH入门1JMH介绍JMH是JavaMicroBenchmarkHarness的简写,是专门用于代码微基准测试的工具集(toolkit)。JMH是由实现Java虚拟机的团队开发的,因此他们非常清楚开发者所编写的代码在虚拟机中将会如何执行。由于现代JVM已经变得越来越智能,在Java文件的编译阶段、类的加载阶段,以及运行阶段都可能进行了不同程度的优化,因此开发者编写的代码在运行中未必会像自己所预期的那样具有相同的性能体现,JVM的开发者为了让普通开发者能够了解自己所编写的代码运行的情况,JMH便因此而生。

    2022年7月27日
    3
  • 微信支付-支付结果通知接收「建议收藏」

    微信支付-支付结果通知接收「建议收藏」微信支付-支付结果通知接收最近在做微信支付功能在微信成功后,微信通过异步方式返回支付结果是遇到了问题:参数接收不到。后来通过查阅资料才将问题解决,现在将解决方法分享一下。官方文档解释如上图所示:通过微信支付时要先在微信支付系统生成预付订单,然后才能在前台发起支付请求。生成预付订单时会向微信支付系统传递一个参数:notify_url。下面是该参数的解释:微信对这个回调路径没有特殊要求,不需要授权目录下

    2022年5月29日
    44
  • 浏览器添加HackBar[通俗易懂]

    浏览器添加HackBar[通俗易懂]以火狐浏览器为例第一步:打开浏览器第二步:搜索HackBar–>添加第三步:验证【六礼】冠、婚、丧、祭、乡饮酒、相见【六艺】礼、乐、射、御、书、数【六义】风、赋、比、兴、雅、颂…

    2022年6月12日
    23

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号