小小代码留着有用【自己做项目学到得就是比老师交的映像深刻】

来源:互联网 发布:解压缩软件手机版 编辑:程序博客网 时间:2024/05/17 06:17

1.实现居中
在td标签中加入属性align="center"(这个是左右居中)valign="middle"(这个是上下居中)
例:
<table>
<tr><td align="center" valign="middle">图片文字居中现实代码</td></tr>
</table>
2.绝对定位
<style type="text/css">
         #div3
       {
        position:absolute;
        top:100px;
        right:267px;  
      }       
        
 </style>
3.图片去边框
img
{
    border:none;}
4.超链接去下滑线
 a
{
 text-decoration:none;
}

<a href="连接到得页">作业</a>

5.将盒子的边框显示出来
 
<div id="div2" style="border: 2px solid Red; width:211px; height:563px;">
设置盒子在指定的位置
<div id="hezi" style="border: 1px solid Red;width:800px; height:350px; text-align:center;margin-left:200px;position:relative;top:120px; "  >

6.加*并使*变成红色
<span class ="w">*</span>
 .w
    {
                  
        color:Red ;
    }
7、设置一个图片按钮
 <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/zhanglan/zhuze.jpg" />
8.验证码
<td id ="d"><img id="yanzhengma" src="yanzhengma.aspx" onclick="this.src='yanzhengma.aspx?aaa='+new Date()" alt="" />
            <a href="javascript:Verify();">看不清楚,换张图片 </a>
            </td>


<script type="text/javascript" >

      function Verify()
       {
          document.getElementById("yanzhengma").src = "yanzhengma.aspx?time=" + Math.random();
      }
  </script>

 

protected void Page_Load(object sender, EventArgs e)
        {
            System.Random r = new Random();
            string s = Convert.ToString(r.Next(1000, 9999));//验证码数字
            string path = Server.MapPath("~/images/zhanglan/1.jpg");
            using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(path))
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
                {

                    g.DrawString(s, new System.Drawing.Font("宋体", 30), System.Drawing.Brushes.Red, 0, 0);
                }
                bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            Session["index"] = s;

        }


----------------------------------------------------
9.图片按钮转向另一个界面
 protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("~/Resiger.aspx");
           
        }


 <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/img/新用户注册.png"
                      onclick="ImageButton2_Click" />

设置属性:validationGroup
------------------------------------------------------------
10.验证文本框TextBox是否为空
   1.使用工具箱控件 RequiredFieldValidator
   2.设置属性ControToValidate 设置为你想验证的文本框
   3.将验证字的颜色设置为红色 ,把ForeColor属性设置为red

-------------------------------------------------------------------------------

11.3秒后页面跳转
  <meta http-equiv="Refresh" content="3;URL=http://www.163.com" />
  <script type="text/javascript">
      var the_timeout; the_timeout = setTimeout("Refresh();", 3000);
      function Refresh() { window.location.href = "main.aspx"; }
  </script>

----------------------------
12.实现默认情况为为本框(用户名/邮箱),当为本框为空光标移动到别的地方时仍显示(用户名/邮箱)
  <script type="text/javascript">
     function onfocus1() {
         document.getElementById("Text1").value = "";

     }
     function onfocus2() {

         if (document.getElementById("Text1").value =="") {
             document.getElementById("Text1").value = "用户名/邮箱";
         }

     }

 </script>

<input runat="server" id="Text1" type="text" value="用户名/邮箱" onfocus="onfocus1();"/>
<input runat="server" id="Text2" type="text"  onfocus="onfocus2();"/>
-------------------------------------------
13.web.config里连接数据库
<?xml version="1.0" encoding="utf-8"?>

<!--
  有关如何配置 ASP.NET 应用程序的详细消息,请访问
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

  <connectionStrings>
   
    <add name="conStr" connectionString="data source=EJNSWJOZ0JSDS7J;Initial

Catalog=CSDNBoKe;User ID=sa;Password=111111; "/>
  </connectionStrings>
 
</configuration>

 

混合身份登录:
Data Source=YHB-PC;Initial Catalog=MyTest;Persist Security Info=True;User

ID=sa;Password=yhb@163
windows登录:
Data Source=YHB-PC\SQLSERVER2008;database=csdnnews;integrated security=true
连接SQLExpress
Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated

Security=True;User Instance=True


 

原创粉丝点击