版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.WEB应用技术Request.UserHostAddress 可得到用户IP应用:用于防止用户对某些特定的操作重复执行.(登陆第一次时把此用户IP保存一个session对象变量中 int i = 5; string sd DateTime d1, d2; d1 = System.DateTime.Now;/取得系统当前时间 d2 = Convert.ToDateTime("2008-12-21"); sd = Convert.ToString(d2).Substring(0,10); s=”abcdefg” s1=s.substring(3,2)=”de”/把一个长日期时
2、间格式的数据转换为只要日期,如:2012-11-120 使用DIV控制层的显示和隐藏 见test3下的DIV.ASPX生成一个DIV,给ID和name属性赋值,设置其style属性”定位”,”边框”等参数如果要想DIV成一个指定大小的框,应指定定位参数如果要想DIV开始时不显示,设置其“布局”参数为none(block为显示出来)这个例子适合于广告,或重要信息的显示.(1) 控制DIV轮流显示 if (document.getElementById("div1").style.display = "block") document.getElementB
3、yId("div1").style.display = "none" else document.getElementById("div1").style.display = "block" (2)控制DIV1 走S,还可以停下来left1 = 1; top1 = 1 var fx = 1; /向右跑 var t; function Button4_onclick() top1 = top1 + 3; if (fx = 1) left1 = left1 + 10; document.getElementById(&
4、quot;div1").style.left = left1; /注意:单位默认为px document.getElementById("div1").style.top = top1; if (left1 > 800) fx=0; /向左跑 if (fx = 0) left1 = left1 - 10; document.getElementById("div1").style.left = left1; /注意:单位默认为px document.getElementById("div1").style.top =
5、top1; if (left1 <= 0) fx = 1; document.getElementById("Text2").value = top1; / if (top1 > 30) clearTimeout(t); 放在这里控制timerout失效是错误的,因t赋值在后面 t=setTimeout(stopt, 200); function stopt() if (top1 > 400) clearTimeout(t); else Button4_onclick(); 一 如何控制文本框中输入的内容只能是数字:方法1:对文本框录入数据后,整体判断,可
6、实现但不常用 protected void Button1_Click(object sender, EventArgs e) int n; string s; s = TextBox1.Text.Trim(); int flag = 1; for (int i = 0; i < s.Length; i+) if (!(string.Compare(s.Substring(i, 1), "0") > 0 && (string.Compare(s.Substring(i, 1), "9") < 0) flag = 0; b
7、reak; if (flag = 1) n = int.Parse(TextBox1.Text); n = int.Parse(Math.Pow(n, 2).ToString(); TextBox2.Text = n.ToString(); else TextBox2.Text = "数据输入有误" 方法2:使用javascript脚本实时判断并过滤见test3下的onlynum.aspx:<script language="javascript" type="text/javascript"> function chec
8、k1() if (!IsNum(event.keyCode) var st = document.getElementById("Text2").value; document.getElementById("Text2").value = st.substring(0,st.length-1);/消去刚才输入的非法字母 function IsNum(KeyCode) /只允许0-9之间,或者是backspace、DEL键 if(KeyCode>47)&&(KeyCode<58)|(KeyCode=8)|(KeyCode=46
9、) return true; else return false; </script> <input id="Text2" name="Text2" type="text" onkeyup="check1()" />方法3:使用正则表达式:不好理解<input id="Text1" type="text" onkeyup="value=value.replace(/W/g,'') "onbeforepaste=
10、"clipboardData.setData('text',clipboardData.getData('text').replace(/d/g,'')/"> 只能输入数学和字母(调用系统自带的replace方法,代码最简单<br />二 如何实现把字符中转换为控件名,从而实现批量操作控件,非常实用见test3下的stringtocontrol.aspx例子:C#的语法 string str="TextBox1"winForm CS模式下的窗体 (TextBox)(this.Control
11、s.Find(str, true)0).Text = "OK " WebForm BS模式的WEB(TextBox)(this.form1.FindControl(str).Text = "OK " 前台:分别做两个3*3的表格,第一个表格内放Label1-9;第二个表格内放 ImageButton1-9<div align="center"> <table style="width:80%; height: 179px;" border="1"> <tr>
12、<td class="style2"> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </td> <td class="style2"> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <
13、/td> <td class="style2"> <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label> </td> </tr> <tr> <td class="style4"> <asp:Label ID="Label4" runat="server" Text="Label&q
14、uot;></asp:Label> </td> 省写 </table> </div> <br /> <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" /> </p> <div align="center" > <table style="width:50%;" bo
15、rder="2"> <tr> <td class="style7"> <asp:ImageButton ID="ImageButton1" runat="server" Height="150px" Width="200px" ImageUrl="/img/2.jpg" /> </td> <td class="style7"> <asp:ImageButton ID
16、="ImageButton2" runat="server" Height="150px" Width="200px" /> </td> <td class="style7"> <asp:ImageButton ID="ImageButton3" runat="server" Height="150px" Width="200px" /> </td> </t
17、r> 省写 </table></div>后台:protected void Button1_Click(object sender, EventArgs e) string s = "label1" (Label)(this.form1.FindControl(s).Text = "aaaa" string s1 = new string10; Random x = new Random(); for (int i = 1; i <= 9; i+) s1i = "label" + i.ToStrin
18、g().Trim(); for (int i = 1; i <= 9; i+) (Label)(this.form1.FindControl(s1i).Text = x.Next(26).ToString()+ (char)( x.Next(26)+65); protected void Button2_Click(object sender, EventArgs e) for (int i = 1; i <= 9; i+) (ImageButton)(this.form1.FindControl("ImageButton"+i.ToString().Trim(
19、).ImageUrl="/img/"+i.ToString()+".jpg" ; 三 AJAX不刷新专讲此例内容: ajaxhtmwebconfirmsamp1文件夹下的例子1 ajax下的html和web控件混用,不刷新问题2 输出数据库数据时同时,添加链接,且加上删除数据的confirm确定对话框前言: 在以前,不刷新本身在软件开发过程中是一个难题,最近MS在慢慢解决这个问题,让服务器控件也能实现前面HTML控件的大部分功能,就是所谓的AJAX技术,目前已经有多种AJAX方法,但都不是很完美的 ; 在大部分情况下,为了尽可能减少服务器负担,我们还要大量使用html控件,使用javascript方法来控制一些简单的流程,故一个程序界面中会出在html控件和服务器控件混杂使用的情况下.防止数据被莫名其妙地刷新丢失,可使用ajax的控件,目前VS2008以上版本都支持(不需要编写大段代码) 手工设置标准web服务器控件的autoposeback属性:我们可控制它是否刷新,向服务器是否回传动作(如果设置为true才会回传服务器,否则它是静态的,不会回传,也
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025 高中信息技术数据与计算之数据在互联网金融资产定价模型优化中的应用课件
- 2025 高中信息技术数据与计算之数据仓库的 ETL 数据清洗效果评估课件
- 2026年欧盟CBAM与WTO合规性争议及中欧贸易争端风险分析
- 2026年高校量子教研机房建设与尖端人才培育实务
- 2026年听力健康正成银发经济蓝海市场机遇手册
- 2026年以房养老市场规模与需求趋势研判
- 2026年智能体演进责任认定与业务流程重构应对方案
- 下肢静脉曲张的临床诊断与鉴别诊断
- 2026年中医馆小程序预约系统搭建与线上预约占比突破90%攻略
- 2026中国科学院上海药物研究所刁星星课题组样品处理及分析人员招聘1人备考题库附答案详解【模拟题】
- 数据出境安全协议
- 护士交接班礼仪
- 胰岛素抵抗病症典型症状及护理指南
- 水专题测试卷-高考地理二轮复习讲练测(解析版)
- 2025年10月自考05677法理学试题及答案含评分参考
- 2025年专升本旅游管理历年真题汇编试卷及答案
- 2026年辽宁医药职业学院单招职业适应性测试必刷测试卷及答案1套
- 招投标实务培训
- 2025年北京省考行测笔试真题(附含答案)
- EP28-A3c 临床实验室中参考区间的定义、建立和验证(中文下载)
- 国家能源集团笔试试题及答案
评论
0/150
提交评论