相信大家在项目中也会用到一些小技术点,我就当抛砖引玉..........................................................
1,JS,CSS引用路径
大家在项目常会用到引用外部的JS脚本或CSS,等 相信大家都会觉得这没什么可说的,真接将CSS拖进页面即可???????
对这种操作没错,但大家想过没有,如何有一天你的文件路径改变了(例如, 你以前的.aspx 页路径在(../Web/UI/default.aspx) 与 .js文件路径在(../Web/JS/public.js)
现在你的.aspx页面路径改变了,变成(../Web/UI/Common/default.aspx)请问这样你们直接引用的JS还能起作用吗(大家试试..........................)不能的.为什么呢???
因为你的src=".." 代表是找上一级,但现在你的.aspx页面上一级UI级是没JS这个文件夹的,所以引且不到js脚本,所以要改成这样
你可以将下面的GetURL方法写在BasePage类中,页面只要继承此类.
/// Get a absolute path with ApplicationPath.
/// </summary>
/// <param name="pageAddress"> Relative page address </param>
/// <returns> A absolute path with ApplicationPath </returns>
protected string GetURL( string pageAddress)
{
return HttpContext.Current.Request.ApplicationPath + " / " + pageAddress;
}
2,控件包含代码块<%%>,因此无法修改控件集合的解决方法
造成这个错误的原因是在<head runat = "server"></head>里面,使用到类似的这样代码<%%>,
解决方法是,将这样的代码放到Body 中即可
3,常看到csdn上有这种脚本,随着输入的字段多少,textbox也作相应的字符递减.
function textCounter(field, countfield, maxlimit) {
countfield.value = maxlimit - field.value.length;
if (field.value.length > maxlimit) {
countfield.style.color = ' #FF0000 ' ;
}
}
function textReset(field, countfield, maxlimit) {
if (field.value.length > maxlimit) {
alert( ' 描述超长,将截掉超限部分! ' );
}
field.value = field.value.substring( 0 ,maxlimit);
countfield.style.color = ' #000000 ' ;
countfield.value = maxlimit - field.value.length;
}
HTML代码
< asp:TextBox runat = " server " TextMode = " MultiLine " ID = " txtDes " class = " textarea " Rows = " 5 "
onkeydown = " textCounter(this.form.txtDes,this.form.count_0,200); " onblur = " textReset(this.form.txtDes,this.form.count_0,200); "
onkeyup = " textCounter(this.form.txtDes,this.form.count_0,200); " onchange = " textCounter(this.form.txtDes,this.form.count_0,200); " ></ asp:TextBox >
< input type = " text " name = " count_0 " readonly value = " 200 " />
4,ajax控件实现验证必输项,与必选项
相信上面的这种弹出式提示验证必输项,大家都用过 AjaxControlToolkit 组件都知道会用,
< asp:RequiredFieldValidator ID = " RequiredFieldValidator1 " ControlToValidate = " txtName "
runat = " server " ErrorMessage = " 员工姓名不能为空 " Display = " None " ></ asp:RequiredFieldValidator >
< ajx:ValidatorCalloutExtender ID = " ValidatorCalloutExtender1 " runat = " server " TargetControlID = " RequiredFieldValidator1 "
WarningIconImageUrl = " ~/images/alert-small.gif " Width = " 150px " >
</ ajx:ValidatorCalloutExtender >
查有时会出现这种情况,不知道大家相过如何实现吗
其实也可以 AjaxControlToolkit 组件中的 ValidatorCallOUtExtender 实现,但是如何验证才能证他弹出呢,很简单,我在
给dropdownList 赋值时给出的
所以在验证时,我们就可以根据他选择的 selectedValue值来判断验证是否大于0
</ asp:DropDownList >
< asp:RangeValidator ID = " RangeValidator1 " runat = " server " Display = " None " MinimumValue = " 1 " // 注意这里minimumvalue值,因为我第一项是请选择..的value 为0 所以这里至少要大于0
MaximumValue = " 10000 " // 这里给出的10000,你可以随便给,10000已经足够用了
ControlToValidate = " drpOrgList " ErrorMessage = " 组织机构为必选项 " Type = " Integer " ></ asp:RangeValidator >
< ajx:ValidatorCalloutExtender ID = " ValidatorCalloutExtender7 " runat = " server " TargetControlID = " RangeValidator1 "
WarningIconImageUrl = " ~/images/alert-small.gif " Width = " 150px " >
</ ajx:ValidatorCalloutExtender >
好了,就说这么多,以后有小技术点再补充..................................... 大家的技术才我最大的动力