• asp。net:html的表单元素:


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" %>
    
    <!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 type="text/css">
            .la1 {
                 200px;
                height: 200px;
                background-color: blue;
                border: 10px solid black;
                display: inline-block;
            }
        </style>
    
        <script type="text/javascript">
            function TiShi() {
                alert('你好');
            }
    
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:TextBox ID="TextBox1" runat="server" MaxLength="6" OnTextChanged="TextBox1_TextChanged" ReadOnly="True">fsdfsdfsdf</asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="alert('这是JS');" />
            <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    
    
    
    
            <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
            <asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" />
    
    
    
    
        </form>
    </body>
    </html>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Default1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Literal1.Text = "你好啊";
    
        }
        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Literal1.Text = "你好啊";
        }
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
    
        }
    }


    文本类:
    <input type="text"/>
    <input type="password"/>
    <input type="hidden"/>
    <textarea />

    按钮类:
    <input type="submit" />
    <input type="button" />
    <input type="reset" />
    <input type="image" />

    选择类:
    <input type="radio"/>
    <input type="checkbox"/>
    <input type="file" />
    <select>
    <option></option>
    </select>

    复合控件:

    CheckBoxList - 复选框组,可以添加无数个复选框,每一个都是一个ListItem,而这些项都放在了复选框组的Items集合中
    单选 - 复选框组.SelectedItem来选出选中的项
    多选 -
    if (CheckBoxList1.SelectedIndex > -1) //阻止未选择报错的情况
    {
    Label1.Text = "";
    //遍历全部的项,看看如果是被选中了,就。。。。
    foreach (ListItem li in CheckBoxList1.Items)
    {
    if (li.Selected)
    {
    Label1.Text += li.Text;
    }
    }
    }

    RadioButtonList - 单选框组
    可以添加无数个单选框,需要注意的属性与上面一样,
    唯一需要注意的:单选框组要注意分组

    FileUpload - 文件选择对话框
    获取选中的文件路径 - FileUpload1.FileName
    但是此时获取的仅仅是相对路径,如何转换成绝对路径?
    string path = Server.MapPath(FileUpload1.FileName);

    =======================注意=======================
    web端 - 无状态性 每一次事件提交都会刷新页面,而刷新后的页面与之前你看到的页面就不再是同一个页面了

    每一次页面刷新都会走一遍PageLode事件,那么里面的某些代码我们只需要让它在页面第一次加载的时候才需要执行,那么需要增加判断:
    if(IsPostBack == false)
    {
    XXXXX
    }
    =======================注意=======================
    DropDownList - 下拉列表框 - 单选

    ListBox - 列表框 - 多选 SelectionMode属性来设置单选或多选

  • 相关阅读:
    dlib库+vs2017详细配置流程
    【网易云课堂】【中科院团队】深度学习:算法到实战——神经网络基础
    【网易云课堂】【中科院团队】深度学习:算法到实战——绪论
    matlab 读取多行txt文本
    LeetCode 228. Summary Ranges【未加入列表】
    LeetCode 438. Find All Anagrams in a String
    c++冷知识
    python项目实战——西游记用字统计
    LeetCode 101. Symmetric Tree
    LeetCode 63. Unique Paths II
  • 原文地址:https://www.cnblogs.com/zhangdemin/p/5681672.html
Copyright © 2020-2023  润新知