• 009. 简单的注册页和重置


    前端html代码

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!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 >
            <table style="500px ; text-align:left; margin:auto;">
                <tr>
                    <td  style="text-align:right">
                        <asp:Label ID="Label1" runat="server" Text="用户名:"></asp:Label>
                        </td>
                    <td>
                        <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td  style="text-align:right">
                        <asp:Label ID="Label2" runat="server" Text="密码:" ></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtpwd" runat="server" TextMode="Password"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td   style="text-align:right; left:50px;">
                        <asp:Label ID="Label3" runat="server" Text="性别:"></asp:Label>
                    </td>
                    <td>
                        <asp:RadioButtonList ID="rblsex" RepeatDirection="Horizontal" 
                            runat="server" 
                            Width="173px">
                            <asp:ListItem Selected="True"></asp:ListItem>
                            <asp:ListItem></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                   <tr>
                    <td   style="text-align:right">
                        <asp:Label ID="Label4" runat="server" Text="住址:"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtaddress" runat="server"></asp:TextBox>
                    </td>
                </tr>
                    <tr>
                    <td colspan="2" style="text-align:center;">
                        <asp:Button ID="btnreg" runat="server" Text="注册" onclick="btnreg_Click" />   &nbsp; &nbsp;
                        <asp:Button ID="btncancel" runat="server" Text="重置" onclick="btncancel_Click" />
                    </td> 
                </tr>
            </table>
        </div>
        </form>
    </body>
    </html>

    后台CS代码(含如何向客户端发送js代码)

        protected void btnreg_Click(object sender, EventArgs e)
        {
            if (txtname.Text.Length == 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请输入用户名')", true);
            }
            else
            {
                if (txtpwd.Text.Trim().Length == 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请输入密码!')", true);
                }
                else
                {
                    if (txtaddress.Text.Trim().Length == 0)
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请输入地址!')", true);
                    }
                    else
                    {
                        this.gender = rblsex.SelectedItem.Text;
                    }
                }
            }
            /*
            if (rblsex.SelectedIndex == 0)
            {
                // Page.ClientScript.RegisterClientScriptBlock():添加脚本块, 页面加载前执行
                //RegisterStartupScript 注册脚本并在页面加载完时执行。
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('男')", true);
                //Page.ClientScript.RegisterClientScriptInclude
                //把JavaScript放置在.js文件中,使用RegisterClientScriptInclude方法可以注册.js文件中的 JavaScript
                //string myScript = “myJavaScriptCode.js”
                //Page.ClientScript.RegisterClientScriptInclude(“myKey”, myScript);
                //这将在ASP.NET页面产生如下结构:
                //<script src=”myJavaScriptCode.js” type=”text/javascript”></script>
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('女')", true);
            }
             */
        }
        protected void btncancel_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Page.Controls.Count; i++)
            {
                foreach (Control item in Page.Controls[i].Controls)
                {
                    if (item is TextBox)
                    {
                      ((TextBox)item).Text=""; //对象转换
                      
                    }
                }
            }
        }
  • 相关阅读:
    Android性能测试工具APT使用指南
    android.app.Activity阅读摘要,有时候会不会需要保持一些现场数据呢? 想让系统帮你退出到后台或者挂掉前做些前置保持工作吗,重点参考吧:
    OkHttp+Stetho+Chrome调试android网络部分
    HLG2179 组合(dfs水水更健康)
    HLG 1494网络 (求的割点数目)可做模板
    hdu2586&&poj1330 求点间最短距&&最近公共祖先(在线&&离线处理):::可做模板
    hdu 2586
    poj分类
    poj3748 位运算 bitset
    C++ bitset类的使用与简介
  • 原文地址:https://www.cnblogs.com/wxylog/p/6051098.html
Copyright © 2020-2023  润新知