1.让ImageButton控件背景透明的方法
<asp:Button ID="ImageButton1" runat="server" style="background:url(); cursor:hand;" BorderWidth="0" Text="进入系统" /> 靠的就是background:url()这句代码
2.TextBox控件自动完成技巧
TextBox 控件有什么新鲜事?嗯!有个看似很小但却常来困扰的小改良,就是“自动完成” (AutoComplete)。何谓自动完成呢?也就是TextBox 会记忆用户曾经输入过文字,当下次再 次输入时就会自动提示相关字词,最常见的是用户登录网站时就会自动带出账号和密码。 这个功能在最早被发明时大家觉得很方便很好用,但随着信息安全意识的加强,这个功能 有时不但不讨人喜欢,反而有点令人厌恶,为什么呢?现在无论是在家中、网吧还是公司,多 人共享一台计算机的机会很多,而也是由于TextBox 的自动完成在作祟的缘故,他人要看你的 E-Mail 甚至假借您的账号登录网页并非难事,只要在TextBox 中选取你的账号后,密码通常会 一并自动带出。 关于这个恼人的问题,我接连被朋友问道该如何解决?在ASP.NET 2.0 的TextBox 控件内 置的AutoCompleteType 属性可以轻易解决这个问题,只要将TextBox 的AutoCompleteType 设置为“Disable”后,自动完成提示便完全不会出现。
3.ASP.NET中div定位
<table> <tr><td style="position: relative;"><asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>//按钮 <asp:Button ID="Button3" runat="server" Text="Button" OnClick="Button3_Click" /> <div id="div1" runat="server" style="z-index:1; display:none; position: absolute; left: 0px; top: 20px;"> </div> </td></tr> <tr><td> </td></tr> </table> 如果想控制一个层显示,但是还不想这个层把页面撑开,那么就要设置这个层的position:absolute(绝对定位)。然后代码中设置他的display属性,display:bolock是显示层,none是隐藏层。但是只设置层的position: absolute会遇到麻烦,当页面大小发生改变时,层的位置就不对了,为了克服则必须设置div的父级定位:本例就设置div的父级<td>,将<td>的position: relative(相对定位),然后再设置好div的left和top,这样无论页面放大或缩小,div始终保持和文本框相对的位置,还不会撑开页面。
4.后台设置DIV的内容
protected void TextBox1_TextChanged(object sender, EventArgs e)//单击按钮控制层显示 { div1.Style["display"] = "block";
div.InnerHTML="要设置的内容" }
注意:这里之所以能控制是因为设置了div的runat="server"
5.ASP.NET页面框架跳转 框架内页面跳转到框架外: Response.Write("<script>top.location.href='../Login.aspx';</script>"); 框架外页面跳转到指定的框架内: Response.Write("<script>parent.frames['框架Name属性'].location.href='../Login.aspx';</script>");
6.vs2005中body的颜色问题
body的颜色默认是白色,但是如果在vs2005中设置了body的颜色后,整个页面所有Table的背景色如果不设置,则Table默认为透明的,显示body的颜色!
在VS2005建立的Web窗体中,少了这行代码样式表文件就不起作用了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd"> 具体问题还要进一步研究
7.给服务器控件添加onmouseover,onmouseout等属性
在VS2005中拖拽一个按钮到页面中,按钮没有onmouseover,onmouseout等属性,强行写入虽然vs2005中不认,但是是有效的!所有服务器控件均以此类推! <asp:Button ID="Button1" runat="server" Text="登录" CssClass="btn1_mouseout" onmouseover="this.className='btn1_mouseover'" onmouseout="this.className='btn1_mouseout'" OnClick="Button1_Click1" />
8.后台执行弹出窗口代码
protected void Button2_Click(object sender, EventArgs e)//后台执行弹出窗口代码 { this.Page.RegisterStartupScript("aaa", "<script type=/"text/javascript/">window.open('../TWXY_SYS/UseShow.aspx','_self','width=400,height=300,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no');</script> "); }
9.后台写javascript写法
protected void Page_Load(object sender, EventArgs e) { this.Page.RegisterClientScriptBlock("_autoPostBack", " <script type=/"text/javascript/"> function document.onkeydown(){ if (event.keyCode == 13){ document.getElementById('" + Button1.ClientID+ "').click(); }} </script> "); }
10.网页引入样式表文件的方法
<link id="css1" type="text/css" runat="server" rel="stylesheet" />
11.后台调用前台javascript函数的方法,后台获得前台html标签的方法
protected void Page_Load(object sender, EventArgs e) { Page.RegisterStartupScript("aaa", "<script>showDetail();</script>"); }
前台写HTML标签,只要给标签加个name属性,那么后台就可以用Request.Form["name"]来获得这个标签
12.得到指定月份的第一天和最后一天
int year = 2008; int month = 6;
DateTime FirstDay = new DateTime(year, month, 1); DateTime LastDay = FirstDay.AddMonth(1).AddDays(-1);
13.asp.net中调用outlook邮件界面
<a href="mailto:email@address1.com,email@address2.com?cc=email@address3.com&Subject=Hello&body=Happy New Year ">点击我</a>
mailto:后面可以加4种参数
mailto:地址1,地址2,...地址N?cc=抄送的内容&Subject=主题的内容&body=邮件主体内容 //红色符号和字体为连接关键字
14.如何使Windows Form上的Panel或者Label控件半透明?
通过设置控件背景色的alpha值 panel1.BackColor = Color.FromArgb(65, 204, 212, 230); 注意:在设计时手动输入这些值,不要用颜色选取
15.如何在用一个数据源DataTable绑定两个控件,确保变化不反映在两个控件中?
我们在一个Form中放置一个ListBox和一个ComboBox控件,当数据源是一个DataTable而且绑定的ValueMember一致的时候我们选择ListBox中的一个Item时,ComboBox控件中的相同的Item也会被自动选中,我们可以采取建立新的上下文绑定对象来拒绝这样的同步操作 comboBox1.DataSource = dataset.Tables[ "Items " ]; comboBox1.ValueMember = "CustomerID "; comboBox1.DisplayMember = "CustomerID ";
listBox1.BindingContext = new BindingContext(); // 设置新的上下文绑定对象 listBox1.DataSource = dataset.Tables[ "Items " ]; listBox1.ValueMember = "CustomerID "; listBox1.DisplayMember = "CustomerID ";
16.判断闰年
public static boolean isLeapYear(int year) { boolean isLeapYear = false; int gregorianCutoverYear = 1582;//1582 年定的 Gregorian Calendar 才再增加百年不潤四百年潤的規則 if( year >= gregorianCutoverYear ) { if((year%4 == 0) && ((year%100 != 0) || (year%400 == 0))) { isLeapYear = true; } } else{ if(year%4 == 0) { isLeapYear = true; } } return isLeapYear; }
|