[聚合文章] ASP.NET常用的一些服务器控件

.Net 2017-11-07 1 阅读

文本框控件TextBox, TextMode:值SingleLine表示单行文本,MultiLine表示多行文本,等等。

textbox.jpg

下拉列表控件DropDownList,单项按钮控件Radio,复选框控件CheckBox,等

以一个文本框的实现,来说明这些控件吧。

用vs2015建立完整,过程看图。

新建------>网站

1.jpg

选择C#,ASP.NET空网站

2.jpg

添加---->新添新项

3.jpg

选择Web窗体

4.jpg

展开相关文件

5.jpg

工具箱,有服务器控件,点击TextBox

6.jpg

编辑TextBox1的属性

7.jpg

添加CheckBox控件

8.jpg

设置CheckBox的名字

9.jpg

10.jpg

通过控件等得到的aspx文件。

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

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        文本框选择:<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" Text="加粗" />
        <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" Text="斜体" />
        <asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="True" Text="下划线" />
  字体:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem Selected="True">12</asp:ListItem>
            <asp:ListItem>16</asp:ListItem>
            <asp:ListItem>25</asp:ListItem>
            <asp:ListItem>30</asp:ListItem>
            <asp:ListItem>36</asp:ListItem>
        </asp:DropDownList>
  颜色:<asp:RadioButton ID="Red" runat="server" AutoPostBack="True" ForeColor="#FF5050" GroupName="color" Text="红色" />
        <asp:RadioButton ID="Green" runat="server" AutoPostBack="True" ForeColor="Lime" GroupName="color" Text="绿色" />
        <asp:RadioButton ID="Yellow" runat="server" AutoPostBack="True" ForeColor="Yellow" GroupName="color" Text="黄色" />
        <asp:RadioButton ID="Blue" runat="server" AutoPostBack="True" Checked="True" ForeColor="Blue" GroupName="color" Text="蓝色" />
        <br />
        <asp:TextBox ID="TextBox1" runat="server" Height="385px" OnTextChanged="Page_Load" TextMode="MultiLine" Width="828px"></asp:TextBox>
    
    </div>
    </form>
</body>
</html>

这是C#相关代码

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

public partial class days_20171107 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CheckBox1.Checked)
            TextBox1.Font.Bold = true;
        else
            TextBox1.Font.Bold = false;

        TextBox1.Font.Italic = CheckBox2.Checked;
        TextBox1.Font.Underline = CheckBox3.Checked;
        TextBox1.Font.Size = int.Parse(DropDownList1.Text);

        if (Red.Checked)
            TextBox1.ForeColor = Color.Red;
        else if (Green.Checked)
            TextBox1.ForeColor = Color.Green;
        else if (Yellow.Checked)
            TextBox1.ForeColor = Color.Yellow;
       else
           TextBox1.ForeColor = Color.Blue;

    }

}

结果如下:

11.jpg

12.jpg

c#语法还有待深入,jsp和asp,真是。。。。。。。

代码百度云

注:本文内容来自互联网,旨在为开发者提供分享、交流的平台。如有涉及文章版权等事宜,请你联系站长进行处理。