page_load刷新问题,我只想执行一次

hypozhong 2009-03-18 04:31:07
我的新闻系统目前是自动发布html,类似于文章管理系统。
由于部分板块需要验证,用户登录后才可访问某板块,若不行就跳到登陆页面。
我在生成html时,在body标签中加入了id
如:<body id="down23">
用js来判断body的id,如果遇到id=“down23”就跳转到CkLogin.aspx页面去验证登陆。
js代码如下:
function window.onload()
{
var chanel=document.body.id;
if(chanel=="down23")
{
window.location.href = "/CkLogin.aspx";
return false;
}
}
跳转到CkLogin.aspx后,当用户没有登陆时,可以跳转到登陆页面,如果验证成功就会跳转到允许浏览的板块。
CkLogin.aspx代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (ChkLogin()) //ChkLogin()是验证是否登陆
{
Response.Redirect("/down/index.htm");
}
else
{
Response.Write("<script language=javascript>alert('您还没有登陆!');window.location.href='UserBox/Login.aspx';</script>");
}
}
}

当用户登陆成功后,页面不停的刷新/down/index.htm。
不知道为何,请高手指点。
...全文
175 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hypozhong 2009-03-19
  • 打赏
  • 举报
回复
有高手帮忙么?有什么好的建议?
hypozhong 2009-03-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 hypozhong 的回复:]
是的,要验证的板块body id也是down23,也就是说down23就是我要验证的板块id,
那我该怎么办????有什么其他的办法可以验证呢?
[/Quote]

有啥其他的办法?
zhxhdean 2009-03-18
  • 打赏
  • 举报
回复
死循环,认同
hypozhong 2009-03-18
  • 打赏
  • 举报
回复
是的,要验证的板块body id也是down23,也就是说down23就是我要验证的板块id,
那我该怎么办????有什么其他的办法可以验证呢?
ustbwuyi 2009-03-18
  • 打赏
  • 举报
回复
你的流程变成了这样.

CkLogin.aspx判断登录=>登录成功跳转到index.html=>加载index.html时onload事件触发=>继续到CkLogin.aspx判断登录....

所以死循环了,页面一直在跳转
zuoming120 2009-03-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ustbwuyi 的回复:]
死循环了

估计你index.html页面body的id也是down23吧
[/Quote]
同意
ustbwuyi 2009-03-18
  • 打赏
  • 举报
回复
死循环了

估计你index.html页面body的id也是down23吧
ustbwuyi 2009-03-18
  • 打赏
  • 举报
回复
死循环了

估计你index.html页面body的id也是down23吧
phoebuswei 2009-03-18
  • 打赏
  • 举报
回复

if (ChkLogin()) //ChkLogin()是验证是否登陆
{
Response.Redirect("/down/index.htm");
}
return;

您不会是写成死循环了吧
跳转到,index.htm然后,htm中在跳转到cklogin。aspx
这不就死了吗??
一 Jeecms安装过程 将解压后得到的jeecms-3.0.2-final文件夹下的root文件夹更名为jeecms拷贝到tomcat 安装目录下的webapps 文件夹下(例如: D:\Tomcat 6.0\webapps\),启动tomcat,在地址栏中输入http://localhost:8080/jeecms, 您将看到第一步安装过程中的《用户许可协议》,勾选“我已经阅读并同意此 协议”,点击下一步, 接下来第二步安装过程中设置系统参数,系统会自动检测出一些配置项,请根据您的实际情 况填写,数据库密码不能为空。 点击提交后进入第三步进入最后的系统安装过程,安装过程可能需要十几秒的等待时间。安 装成功后将提示信息,请再重启Tomcat 完成安装。 Tomcat重启完毕之后,在浏览器的地址栏中输入http://localhost:8080/jeecms, 若系统正常显示默认的站点首页则表示JEECMS 已经顺利安装完成. 附: 系统管理后台登录:http://localhost:8080/jeecms/jeeadmin/jeecms/index.do 用户名:admin 密 码:password 图文安装步骤如下: 将解压后得到的ROOT文件夹拷贝到tomcat安装目录下的webapps文件夹下(例如:D:\Tomcat 6.0\webapps\),启动tomcat,在地址栏中输入http://localhost:8080,您将看到第一步安装过程中的《用户许可协议》,如图一所示,勾选“我已经阅读并同意此协议”,点击下一步, 图一:用户许可协议 接下来第二步安装过程中设置系统参数,系统会自动检测出一些配置项,请根据您的实际情况填写,如图二所示,数据库密码不能为空。 图二:系统参数设置 点击提交后进入第三步进入最后的系统安装过程,安装过程可能需要十几秒的等待时间。安装成功后将提示如图三所示的页面信息,请再重启Tomcat完成安装。 图三:系统安装完成 三、完成安装 Tomcat重启完毕之后,在浏览器的地址栏中输入http://localhost:8080,若系统正常显示默认的站点首页则表示JEECMS已经顺利安装完成.,如图四所示: 图四 站点首页 二 Jeecms项目导入myeclipse 1.在myeclipse中新建一个项目jeecms,将服务器中jeecms项目下web-inf文件夹下内容拷到新建项目中 解压缩jeecms-3.0.2-final-src,在src文件夹下会看到有三个压缩文件,如果只进行普通的二次开发,可以只导入cms这个源码,删除jeecms-cms-identity-3.0.2-final.jar即可,如果进行深入的二次开发,需要导入common和core源码,另导入common-lib下的jar包,删除jeecms-cms- identity-3.0.2-final.jar,jeecms-common-3.0.2-final.jar ,jeecms-core- identity-3.0.2-final.jar这三个jar包,切记:务必进行build path 3.修改jdbc链接,自己导入数据库。 4.把服务器下install\config下的web.xml复制出来覆盖掉新建项目WEB-INF下的web.xml 5.classes下有四个文件,手动烤到myeclipse项目src根目录下中 6.将服务器上jeecms项目删掉,发布新建的jeecms项目。 三 首页的加载过程 在浏览器中输入http://localhost:8080/jeecms,回车 首先进入配置文件web.xml, contextConfigLocation <!----> /WEB-INF/config/application-context.xml /WEB-INF/config/cache-context.xml /WEB-INF/config/captcha-context.xml /WEB-INF/config/jeecore-context.xml /WEB-INF/config/jeecms-context.xml 应用范围内的初始化参数 其中jeecms-context.xml是对标签的初始化 index.html index.shtml index.jhtml 通过以上标签找到应该加载哪一个页面 JeeCmsFront org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/config/jeecms-servlet-front.xml <load-on-startup>2load-on-startup> JeeCmsFront *.jhtml JeeCmsFront *.jspx JeeCmsFront *.jsp JeeCmsFront *.htm 通过servlet配置,可以找到jeecms-servlet-front.xml,在此配置文件的最后有 代码 找到jeecms-servlet-front-action.xml,在此配置文件中有 可以找到类DynamicPageAct,此类是首页模板。 在类DynamicPageAct中有 public static final String TPL_INDEX = "tpl.index"; 找到WEB-INF\languages\jeecms_front下messages_zh_CN.properties配置文件,可以找到对应的首页面 tpl.index=首页(工程中的首页.html文件) 四 标签的配置流程 以cms_content_list为例,首先,每一个标签的声明都是在jeecms-context.xml中进行的, <?xml version="1.0" encoding="UTF-8"?> …… (声明标签对应的类) …… …… …… 此外,在配置文件jeecms-servlet-front.xml中,还有一段对标签的配置 …… …… …… 类ContentListDirective继承自AbstractContentDirective,最主要的是execute方法 public class ContentListDirective extends AbstractContentDirective { /** * 模板名称 */ public static final String TPL_NAME = "content_list"; /** * 输入参数,文章ID。允许多个文章ID,用","分开。排斥其他所有筛选参数。 */ public static final String PARAM_IDS = "ids"; @SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { //获取站点 CmsSite site = FrontUtils.getSite(env); //获取内容列表,可以通过此处进行更改,获取自己数据库中的数据 List list = getList(params, env); Map paramWrap = new HashMap( params); //OUT_LIST值为tag_list,在类DirectiveUtils中声明,将内容列表放入其中 paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(list)); //将params的值复制到variable中 Map origMap = DirectiveUtils .addParamsToVariable(env, paramWrap); //获取的是参数PARAM_TPL,是否调用模板以及调用的模板类型 InvokeType type = DirectiveUtils.getInvokeType(params); //获取传入参数,列表样式,根据不同的参数获取不同的样式列表 String listStyle = DirectiveUtils.getString(PARAM_STYLE_LIST, params); if (InvokeType.sysDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_LIST); } //列表样式模板 env.include(TPL_STYLE_LIST + listStyle + TPL_SUFFIX, UTF8, true); } else if (InvokeType.userDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_LIST); } //列表样式模板路径 WEB-INF\t\cms_sys_defined\style_list\style_2-1.html FrontUtils.includeTpl(TPL_STYLE_LIST, site, env); } else if (InvokeType.custom == type) { //这个模板就是自己声明的,即content_list.html,如果采用自定义模板的话,页面中可以只写上标签,并添加上标签内需要的几个参数,不需要写标签体的内容,会去自动调用模板中的标签体。 FrontUtils.includeTpl(TPL_NAME, site, params, env); } else if (InvokeType.body == type) { body.render(env.getOut()); } else { throw new RuntimeException("invoke type not handled: " + type); } //将variable中的params值移除 DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap); } @SuppressWarnings("unchecked") protected List getList(Map params, Environment env) throws TemplateException { Integer[] ids = DirectiveUtils.getIntArray(PARAM_IDS, params); if (ids != null) { //根据内容ID数组获取文章列表 return contentMng.getListByIdsForTag(ids, getOrderBy(params)); } else { return (List) super.getData(params, env); } } @Override protected boolean isPage() { return false; } } Content_list.html中的内容 [#list tag_list as a]
  • ${a.title}
  • [/#list] 就是简单的将tag_list中的内容,即“paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(list));”中放入的数据遍历出来 style_2-1.html中的内容 主要是对图文列表或标题列表向上滚动的样式的,其中包含两个同样为样式的文件 style_2-1_core.html(图文列表或标题列表向上滚动)和style_1-1_core.html(图文列表或标题列表向上滚动),在此就不做赘述了。 Jeecms是基于Spring注解,在自定义标签时对于实体类和dao service等注意注解的问题。 五 自定义标签及使用自己创建的表的实现过程 下面是我自己定义的标签mycontent_list 首先,在数据库里创建了一个jc_mycontent的表,其中有id,title,content三个字段 其次,创建了一个实体类 public class MyContent { private static final long serialVersionUID = 1L; private Integer id; private String title; private String content; public MyContent () { super(); } ……get set方法 } 接下来是配置hibernate中jc_mycontent表的配置文件 <?xml version="1.0"?> <meta attribute="sync-DAO">false</meta> 与数据库交互的持久层接口 public interface MyContentDao { public List getList(); } 持久层实现类 @Repository//持久层 public class MyContentDaoImpl extends HibernateBaseDao implements MyContentDao { @SuppressWarnings("unchecked") public List getList(){ return find(byNothing()); } private Finder byNothing(){ Finder f = Finder.create(); f.append("from MyContent");//可以在此处添加查询条件或者添加各种方法进行动态查询 f.setCacheable(true); return f; } @Override protected Class getEntityClass() { return MyContent.class; } } 业务层接口 public interface MyContentMng { public List getList(); } 业务层实现类 @Service//业务层 @Transactional public class MyContentMngImpl implements MyContentMng { @Transactional(readOnly = true)//配置事务为只读 public List getList(){ return myContentDao.getList(); } private MyContentDao myContentDao; @Autowired//自动绑定 public void setMyContentDao(MyContentDao myContentDao) { this.myContentDao = myContentDao; } private List listenerList; @Autowired public void setListenerList(List listenerList) { this.listenerList = listenerList; } } 标签类的抽象类,最主要的就是getData这个方法,以及绑定业务层,其中可以添加多种查询方法。可参考类AbstractContentDirective public abstract class AbstractMyContentDirective implements TemplateDirectiveModel { protected Object getData(Map params, Environment env) throws TemplateException { return myContentMng.getList(); } @Autowired protected MyContentMng myContentMng; } 自定义标签中最重要的类继承上边的抽象类 public class MyContentListDirective extends AbstractMyContentDirective { /** * 模板名称 */ public static final String TPL_NAME = "mycontent_list"; @SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { //获取站点 CmsSite site = FrontUtils.getSite(env); //获取内容列表 List list = getList(params, env); Map paramWrap = new HashMap(params); //OUT_LIST值为tag_list,将内容列表放入其中 paramWrap.put(MYOUT_LIST, DEFAULT_WRAPPER.wrap(list)); //将params的值复制到variable中 Map origMap = DirectiveUtils.addParamsToVariable(env, paramWrap); //没有采用默认的模板,直接采用自己写的简单的模板(mycontent_list.html) FrontUtils.includeTpl(TPL_NAME, site, params, env); //将variable中的params值移除 DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap); } protected List getList(Map params, Environment env) throws TemplateException { return myContentMng.getList(); } } 样式模板mycontent_list.html内容,里边可以自己添加一些样式,可参考\t\cms_sys_defined\style_list下样式文件 [#list mytag_list as a]
  • "${a.content}"
  • [/#list] 首页里加入如下代码 [@cms_mycontent_list]
    [/@cms_mycontent_list] 通过以上这些代码,可以实现将自己的表jc_mycontent中的数据查询并显示在页面上 六 标签使用和模板的制作 1模板规划 1.1资源文件 资源文件就是网页中用到的图片、CSS、JS等元素,在CMS系统中所有的资源文件在网站的根目录中的 /res_base/所属网站定义资源目录/TEMPLEATE/WEB /res_base/所属网站定义资源目录/TEMPLEATE/WAP 解释:网站定义资源 在CMS系统中可以同时管理多个网站,也就是多个网站可以同时使用一套CMS系统,但是每一个网站都已属于自己独立的资源文件及模板文件目录。 1.2模板文件 定义了页面显示的主体框架,它的位置位于网站根目录下的/WEB_INF/user_base/所属网站模板目录; 模板规则: 1、以index前缀命名的为首页模板 2、以channel前缀命名的为栏目模板 3、以content前缀命名的为内容模板 4、以alone前缀命名的为栏目单页模板 1.3使用方式 1、使用dw建立站点 2、将网页中用到的资源文件分类分别放置到网站相关资源目录中 3、将模板文件放置按照命名规则分别放置到网站相关模板目录中。 4、将头部、底部等等具有通用元素的模板文件放置到模板目录中的include目录中 5、将模板文件中所有资源引用改为绝对路径链接至资源目录中 6、在栏目管理中将模板文件与栏目进行关联设置 7、在模板文件中需要提取数据的位置放置相应的标签 1.4标签调用样式 调用"JEECMS标签"的三种代码样式如下:   A、${标签名称}   B、[@cms.标签名称 属性='值'/]   C、[@cms.标签名称 属性='值'; 标签别名] 自定义样式模板 [/@cms.标签名称]   例如: a、${web.name}标签用于调用网站名称 b、[@cms.ArtiList chnlId='' count='10' sysContent='1-1' /]标签用于调用 10篇文章的列表 C、[@cms.ChnlList id='' inner='1';c]|>${c.name} [/@cms.ChnlList]标签用于调用栏目列表,可用于网站导航条。   注意:abc实例是与上面ABC三种形式相对应的。大家可以逐个测试,举一反三 2 Include标签 2.1功能简介 做过网站设计经验的朋友可能都知道,我们可以将页面中经常要引用的公共部分(比如页头和页脚)独立开来,单独存放在一个页面中。这样做的好处就是可以在各个需要用到该部分的页面中用一个简单的包含语句就能把它引入进来,大大简化了工作量。 2.2标记说明 【标签名】:[@cms.Include 属性='值' /] 【作 用】:包含公用页面(如页头,页脚) 【参 数】: name:包含模板的文件名 solution:模板方案名 【示 例】: 包含页头:[@cms.Include name='head.html' solution='default'/] 【备 注】:调用此标签前必须先建立相应的包含模板 2.3 明确标签的使用范围   我们在使用任何标签的之前,都必须明确其使用的范围,否则可能无法正常使用该标签。   【Include 标签】的使用范围是:首页模板,栏目页模板,内容页模板,即对应\WEB-INF\user_base\jeecms_com_www\template\article\default\文件夹下的index_××.html模板、channel_××.html模板、content_××.html模板 2.4调试标签了解其使用方法   在使用【Include 标签】之前我们必须保证有可供此标签调用的包含模板,本实例只是起演示作用,为方便起见,这里就不再另外创建被包含的模板了,标签调用的是系统默认模板方案中的的head.html模板。 登录JEECMS后台,进入“模板管理->template->article->default”,点击修改开始时建立的index_demo.html模板(如果没有此模板则按照本文开头的说明创建),进入模板代码模式,填写如下标签代码(为了演示效果美观,本处代码中加入了css,可去除): <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>Include标签测试</title> <link href="${sysResRoot}/front.css" type="text/css" rel="stylesheet" /> <link href="${root}/default/article/css/whole.css" type="text/css" rel="stylesheet" /> <link href="${root}/default/article/css/layout.css" type="text/css" rel="stylesheet" /> </head> <body> [@cms.Include name='head.html' solution='default'/] </body> </html>   点保存按钮,然后返回前台站点首页刷新,得到如下效果: 3 ArtiList标签 3.1功能简介 【ArtiList 标签】在CMS中使用的频率可以说是最高的,通过这个标签,你不仅可以得到一个文章列表,而且可以通过不同的参数组合得到不同的显示效果。比如文章图文列表、文字或图片跑马灯、文字或图片上下循环滚动等等。 使用方式: [@cms.ArtiList chnlId='' count='5' sysContent='1-1' titLen='25' lineHeight='1' dateFormat='4' datePosition='2' headMark='2' target='1'/] 3.2标记说明 【标签名】:[@cms. ArtiList 属性='值' /] 【作 用】:获取文章列表数据 【参 数】: 属性名称 属性说明 默认值 可选值 chnlId 栏目ID,栏目页中可不设置,系统会自动获取当前栏目ID 当前栏目ID 空:显示全站文章列表; 栏目ID:指定栏目文章 attr 文章属性ID 空 1:普通 2:图文 3:焦点 4:头条 5:滚动 sysContent 列表显示方式 1-1 1-1:普通标题列表 1-2:图文列表 2-1:标题列表翻滚 2-2:图文列表翻滚 3-1:焦点图 orderBy 排序方式 0 0:发布时间降序; 1:发布时间升序; 2:固顶降序; 3:置顶降序; 4:日点击降序; 5:周点击降序; 6:月点击降序; 7:季点击降序; 8:年点击降序; 9:总点击降序 recommend 是否推荐 0 0:所有文章 1:推荐文章 titLen 标题长度 20 自定义 target 链接打开目标 0 0:原窗口打开 1:新窗口打开 headMark 文章标题图标 0 0:无图标 1:黑色小圆点 2:红色小圆点 3:蓝色单箭头 4:蓝色双箭头 自定义图标:填写图标路 lineHeight 文章列表每行的行高 空 自定义 bottomLine 每行标题下是否带下划分隔线 0 0:无分隔线 1:默认分隔线 自定义样式:css中定义的样式名称 ctgForm 文章类别形式 0 0:不显示文章类别 1:显示栏目类别 2:显示站点名称 ctgClass 文章类别的css-class 空 自定义css样式的class名 dateFormat 文章发布日期显示格式 0 0:不显示日期 1:”年-月-日 时-分-秒” 格式 2:”年-月-日” 格式 3:”月-日 时-分” 格式 4:”月-日” 格式 datePosition 日期排列位置 1 1:紧跟标题之后 2:右对齐 3:左对齐 isPage 是否显示分页 0 0:否;1:是 count 每页列表显示数量 20 自定义 cssStyle 连接的样式 空 自定义 仅当sysContent='1-2'(图文列表)时,以下标签属性才有效 picWidth 按百分比显示图片宽度 25(即每个图片占总宽度的25%,每行可放四张图片) 自定义 picHeight 每行图片显示高度 110 自定义 仅当sysContent='3-×'(焦点图)时,以下标签属性才有效 flashWidth 焦点图宽度 296(px) 自定义 flashHeight 焦点图总高度 200(px) 自定义 textHeight 焦点图文本高度 20(px) 自定义 仅当sysContent='2-×'(特效显示)时,以下标签属性才有效 rollDisplayHeight 显示区高度 28 自定义 rollLineHeight 行高 28 自定义 rollCols 列数(一行中包含几列) 1 自定义 rollSpeed 滚动速度,值越小越快,最小为1 1 自定义 isSleep 是否停顿 1 0:不停顿; 1:停顿 rollSleepTime 停顿时间,值越大停顿越久 50 自定义 rollCount 一次滚动的行数 1 自定义 rollSpan 一次滚动的像素 1 自定义 其它高级标签属性(用于用户个性设置) searchKey 在标题、tags和描述中搜索指定关键字的文章列表,用于搜索页模板 空 自定义关键字 style 标签内部样式,如果指定sysContent或userContent,则该项无效 1 1:普通列表 sysTpl 指定系统模板 1 自定义 sysContent 系统内容样式 0 自定义 userContent 用户内容样式,当sysContent=1时有效 空 自定义 sysPage 系统分页样式 0 自定义 userPage 用户分页样式,当sysPage=1时有效 空 自定义 upSolution 指定其它模板方案样式 空 自定义 upWebRes 指定其它站点样式 空 自定义 pageClass 分页栏css样式的class名称 空 自定义 pageStyle 分页栏css自定义style样式 空 自定义 3.3 明确标签使用范围   我们在使用任何标签的之前,都必须明确其使用的范围,否则可能无法正常使用该标签。 【ArtiList 标签】的使用范围是:首页模板,栏目页模板,内容页模板, 即对应\WEB-INF\user_base\jeecms_com_www\template\article\default\文件夹下的index_××.html模板、channel_××.html模板、content_××.html模板 3.4 调试标签了解其使用方法   登录JEECMS后台,进入“模板管理->template->article->default”,点击修改开始时建立的index_demo.html模板(如果没有此模板则按照本文开头的说明创建),在模板内容处填写如下标签代码(为了演示效果美观,本处代码中引入了系统默认css,可去除):(1).文章列表 <link href="${sysResRoot}/front.css" type="text/css" rel="stylesheet" /> [@cms.ArtiList chnlId='' count='5' sysContent='1-1' titLen='25' lineHeight='1' dateFormat='4' datePosition='2' headMark='2 target='1'/]  点保存按钮,然后返回前台站点首页刷新,得到如下效果: (2).图文列表 <link href="${sysResRoot}/front.css" type="text/css" rel="stylesheet/> [@cms.ArtiList chnlId='' attr='2' count='5' sysContent='1-2' titLen='25' target='1' picWidth='25' picHeight='110'/]   点保存按钮,然后返回前台站点首页刷新,得到如下效果: 4 Position标签 4.1功能简介 在网站页面中我们经常要显示当前页面的位置,例如:当前位置:首页 > 无线城市> 城市要闻 > 正文。在CMS标签中提供了一个显示页面的当前位置调用标签,只需将该标签放到页面的相应地方,设置好调用参数即可,简单方便。 4.2标记说明 【标签名】:[@cms.Position 属性='值' /] 【作 用】:显示页面的当前位置  【参 数】:   homepage —-首页显示方式。【1:站点简称;自定义】(默认:首页)   title ---内容页显示方式。【0:不显示;1:显示内容标题;自定义】(默认:正文)   split ---分割符号。(默认:“>”)   target ---是否原窗口打开。【0:原窗口打开;1:新窗口打开】(默认:原窗口打开)   class ---链接外部样式,等同于html中的class属性   style ---自定义标签样式,等同于html中的style属性  【示 例】:   [@cms.Position homepage='1' split='|' target='1' /] 【作 用】:显示各栏目列表 【参 数】: 属性名称 属性说明 默认值 可选值 id 父栏目ID 默认为空:自动获取当前栏目ID 空:当前栏目ID; 栏目ID:指定父栏目id orderBy 排序方式 0 0:优先级升序; 1:优先级降序; 2:点击次数升序;3:点击次数降序 isDisplay 是否只获取显示的栏目 1 0:获取所有; 1:只获取显示的栏目 hasContent 是否只获取可以有内容的栏目 0 0:获取所有; 1:只获取可以有内容的栏目 linkClass 链接class样式 空 linkTarget 链接打开方式 0 0:当前窗口; 1:新窗口 sysPage 系统分页样式 0 0:不分页; 1:样式一; 2:样式二 userPage 自定义分页样式。如果指定了系统分页样式,则该项无效 0 0:不分页; 1:样式一; 2:样式二 5.3明确标签的使用范围   我们在使用任何标签的之前,都必须明确其使用的范围,否则可能无法正常使用该标签。 [@cms.ChnlList /]标签的使用范围是:首页模板,栏目页模板,即对应\\WEB-INF\\user_base\\jeecms_com_www\\template\\article\\default\\文件夹下的index_××.html模板、channel_××.html模板 5.4调试标签了解其使用方法 1、单独标签调用示例: [@cms.ChnlList/] 2、自定义标签调用示例:    [@cms.ChnlList id='' inner='1';c,i]     <a href="${c.url}">${c.name}[#if (i+1)%2==0]
    [/#if]    [/@cms.ChnlList] 3、配合其它标签嵌套调用示例: [@cms.ChnlList id='' sysType='article' hasContent='1' inner='1';c]
    ${c.name}
    [@cms.ArtiList chnlId=c.id sysContent='1-1' titLen='20' count='6' /]
    [/@cms.ChnlList] 6内容页常用标签 6.1标记说明 【文章导航】:[@cms.Position /] 【文章标题】:${arti.title} 【简短标题】:${arti.shortTitle} 【文章作者】:${arti.author} 【发布日期】:${arti.releaseDate} 【查看次数】:${arti.visitTotal} 【文章来源】:${arti.origin} 【文章摘要】:${arti.description} 【文章内容】:${arti.content}
    ASP.NET常用代码 1. 打开新的窗口并传送参数: 传送参数: response.write("<script>window.open('*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"')' & name='<%# DataBinder.Eval(Container.DataItem, "数据字段2")%>' /> 7.表格点击改变颜色 if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onclick","this.style.backgroundColor='#99cc00';this.style.color='buttontext';this.style.cursor='default';"); } 写在DataGrid的_ItemDataBound里 if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem) { e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#99cc00';this.style.color='buttontext';this.style.cursor='default';"); e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='';this.style.color='';"); } 8.关于日期格式 日期格式设定 DataFormatString="{0:yyyy-MM-dd}" 我觉得应该在itembound事件中 e.items.cell["你的列"].text=DateTime.Parse(e.items.cell["你的列"].text.ToString("yyyy-MM-dd")) 9.获取错误信息并到指定页面 不要使用Response.Redirect,而应该使用Server.Transfer e.g // in global.asax protected void Application_Error(Object sender, EventArgs e) { if (Server.GetLastError() is HttpUnhandledException) Server.Transfer("MyErrorPage.aspx"); //其余的非HttpUnhandledException异常交给ASP.NET自己处理就okay了 :) } Redirect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可以在错误处理页面得到出错信息并进行相应的处理 10.清空Cookie Cookie.Expires=[DateTime]; Response.Cookies("UserName").Expires = 0 11.自定义异常处理 //自定义异常处理类 using System; using System.Diagnostics; namespace MyAppException { /// /// 从系统异常类ApplicationException继承的应用程序异常处理类。 /// 自动将异常内容记录到Windows NT/2000的应用程序日志 /// public class AppException:System.ApplicationException { public AppException() { if (ApplicationConfiguration.EventLogEnabled) LogEvent("出现一个未知错误。"); } public AppException(string message) { LogEvent(message); } public AppException(string message,Exception innerException) { LogEvent(message); if (innerException != null) { LogEvent(innerException.Message); } } //日志记录类 using System; using System.Configuration; using System.Diagnostics; using System.IO; using System.Text; using System.Threading; namespace MyEventLog { /// /// 事件日志记录类,提供事件日志记录支持 /// /// 定义了4个日志记录方法 (error, warning, info, trace) /// /// public class ApplicationLog { /// /// 将错误信息记录到Win2000/NT事件日志中 /// 需要记录的文本信息 /// public static void WriteError(String message) { WriteLog(TraceLevel.Error, message); } /// /// 将警告信息记录到Win2000/NT事件日志中 /// 需要记录的文本信息 /// public static void WriteWarning(String message) { WriteLog(TraceLevel.Warning, message); } /// /// 将提示信息记录到Win2000/NT事件日志中 /// 需要记录的文本信息 /// public static void WriteInfo(String message) { WriteLog(TraceLevel.Info, message); } /// /// 将跟踪信息记录到Win2000/NT事件日志中 /// 需要记录的文本信息 /// public static void WriteTrace(String message) { WriteLog(TraceLevel.Verbose, message); } /// /// 格式化记录到事件日志的文本信息格式 /// 需要格式化的异常对象 /// 异常信息标题字符串. /// /// 格式后的异常信息字符串,包括异常内容和跟踪堆栈. /// /// public static String FormatException(Exception ex, String catchInfo) { StringBuilder strBuilder = new StringBuilder(); if (catchInfo != String.Empty) { strBuilder.Append(catchInfo).Append("\r\n"); } strBuilder.Append(ex.Message).Append("\r\n").Append(ex.StackTrace); return strBuilder.ToString(); } /// /// 实际事件日志写入方法 /// 要记录信息的级别(error,warning,info,trace). /// 要记录的文本. /// private static void WriteLog(TraceLevel level, String messageText) { try { EventLogEntryType LogEntryType; switch (level) { case TraceLevel.Error: LogEntryType = EventLogEntryType.Error; break; case TraceLevel.Warning: LogEntryType = EventLogEntryType.Warning; break; case TraceLevel.Inf LogEntryType = EventLogEntryType.Information; break; case TraceLevel.Verbose: LogEntryType = EventLogEntryType.SuccessAudit; break; default: LogEntryType = EventLogEntryType.SuccessAudit; break; } EventLog eventLog = new EventLog("Application", ApplicationConfiguration.EventLogMachineName, ApplicationConfiguration.EventLogSourceName ); //写入事件日志 eventLog.WriteEntry(messageText, LogEntryType); } catch {} //忽略任何异常 } } //class ApplicationLog } 12.Panel 横向滚动,纵向自动扩展 13.回车转换成Tab <script language="javascript" for="document" event="onkeydown"> if(event.keyCode==13 && event.srcElement.type!='button' && event.srcElement.type!='submit' && event.srcElement.type!='reset' && event.srcElement.type!=''&& event.srcElement.type!='textarea'); event.keyCode=9; 后台代码 protected void CheckAll_CheckedChanged(object sender, System.EventArgs e) { //改变列的选定,实现全选或全不选。 CheckBox chkExport ; if( CheckAll.Checked) { foreach(DataGridItem oDataGridItem in MyDataGrid.Items) { chkExport = (CheckBox)oDataGridItem.FindControl("chkExport"); chkExport.Checked = true; } } else { foreach(DataGridItem oDataGridItem in MyDataGrid.Items) { chkExport = (CheckBox)oDataGridItem.FindControl("chkExport"); chkExport.Checked = false; } } } 17.数字格式化 【<%#Container.DataItem("price")%>的结果是500.0000,怎样格式化为500.00?】 <%#Container.DataItem("price","{0:¥#,##0.00}")%> int i=123456; string s=i.ToString("###,###.00"); 18.日期格式化 【aspx页面内:<%# DataBinder.Eval(Container.DataItem,"Company_Ureg_Date")%> 显示为: 2004-8-11 19:44:28 我只要:2004-8-11 】 <%# DataBinder.Eval(Container.DataItem,"Company_Ureg_Date","{0:yyyy-M-d}")%> 应该如何改? 【格式化日期】 取出来,一般是object ((DateTime)objectFromDB).ToString("yyyy-MM-dd"); 【日期的验证表达式】 A.以下正确的输入格式: [2004-2-29], [2004-02-29 10:29:39 pm], [2004/12/31] ^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$ B.以下正确的输入格式:[0001-12-31], [9999 09 30], [2002/03/03] ^\d{4}[\-\/\s]?((((0[13578])|(1[02]))[\-\/\s]?(([0-2][0-9])|(3[01])))|(((0[469])|(11))[\-\/\s]?(([0-2][0-9])|(30)))|(02[\-\/\s]?[0-2][0-9]))$ 【大小写转换】 HttpUtility.HtmlEncode(string); HttpUtility.HtmlDecode(string) 19.如何设定全局变量 Global.asax中 Application_Start()事件中 添加Application[属性名] = xxx; 就是你的全局变量 20.怎样作到HyperLinkColumn生成的连接后,点击连接,打开新窗口? HyperLinkColumn有个属性Target,将器值设置成"_blank"即可.(Target="_blank") 【ASPNETMENU】点击菜单项弹出新窗口 在你的menuData.xml文件的菜单项中加入URLTarget="_blank" 如: ...... 最好将你的aspnetmenu升级到1.2版 21.委托讨论 http://community.csdn.net/Expert/topic/2651/2651579.xml?temp=.7183191 http://dev.csdn.net/develop/article/22/22951.shtm 22.读取DataGrid控件TextBox值 foreach(DataGrid dgi in yourDataGrid.Items) { TextBox tb = (TextBox)dgi.FindControl("yourTextBoxId"); tb.Text.... } 23.在DataGrid中有3个模板列包含Textbox分别为 DG_ShuLiang (数量) DG_DanJian(单价) DG_JinE(金额)分别在5.6.7列,要求在录入数量及单价的时候自动算出金额即:数量*单价=金额还要求录入时限制为数值型.我如何用客户端脚本实现这个功能? 〖思归〗 <script language="javascript"> function DoCal() { var e = event.srcElement; var row = e.parentNode.parentNode; var txts = row.all.tags("INPUT"); if (!txts.length || txts.length < 3) return; var q = txts[txts.length-3].value; var p = txts[txts.length-2].value; if (isNaN(q) || isNaN(p)) return; q = parseInt(q); p = parseFloat(p); txts[txts.length-1].value = (q * p).toFixed(2); } 刷新一下,然后就滚动到了最上面,刚才选定的行因屏幕的关系就看不到了 page_load page.smartNavigation=true 25.在Datagrid中修改数据,当点击编辑键时,数据出现在文本框中,怎么控制文本框的大小 ? private void DataGrid1_ItemDataBound(obj sender,DataGridItemEventArgs e) { for(int i=0;i"; private static string ScriptEnd = "PageTarget,string Content) { string ConfirmContent="var retValue=window.confirm('"+Content+"');"+"if(retValue){window.location='"+PageTarget+"';}"; ConfirmContent=ScriptBegin + ConfirmContent + ScriptEnd; Page ParameterPage = (Page)System.Web.HttpContext.Current.Handler; ParameterPage.RegisterStartupScript("confirm",ConfirmContent); //Response.Write(strScript); } ---------------------------------------- 27. 将时间格式化:string aa=DateTime.Now.ToString("yyyy年MM月dd日"); 1.1 取当前年月日时分秒 currentTime=System.DateTime.Now; 1.2 取当前年 int 年= DateTime.Now.Year; 1.3 取当前月 int 月= DateTime.Now.Month; 1.4 取当前日 int 日= DateTime.Now.Day; 1.5 取当前时 int 时= DateTime.Now.Hour; 1.6 取当前分 int 分= DateTime.Now.Minute; 1.7 取当前秒 int 秒= DateTime.Now.Second; 1.8 取当前毫秒 int 毫秒= DateTime.Now.Millisecond; 28.自定义分页代码: 先定义变量 :public static int pageCount; //总页面数 public static int curPageIndex=1; //当前页面 下一页: if(DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1)) { DataGrid1.CurrentPageIndex += 1; curPageIndex+=1; } bind(); // DataGrid1数据绑定函数 上一页: if(DataGrid1.CurrentPageIndex >0) { DataGrid1.CurrentPageIndex += 1; curPageIndex-=1; } bind(); // DataGrid1数据绑定函数 直接页面跳转: int a=int.Parse(JumpPage.Value.Trim());//JumpPage.Value.Trim()为跳转值 if(aPageCount) { this.DataGrid1.CurrentPageIndex=a; } bind(); 29.DataGrid使用: 3.1添加删除确认: private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { foreach(DataGridItem di in this.DataGrid1.Items) { if(di.ItemType==ListItemType.Item||di.ItemType==ListItemType.AlternatingItem) { ((LinkButton)di.Cells[8].Controls[0]).Attributes.Add("onclick","return confirm('确认删除此项吗?');"); } } } 3.2样式交替: ListItemType itemType = e.Item.ItemType; if (itemType == ListItemType.Item ) { e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#FFFFFF';"; e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#d9ece1';cursor='hand';" ; } else if( itemType == ListItemType.AlternatingItem) { e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#a0d7c4';"; e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#d9ece1';cursor='hand';" ; } 3.3添加一个编号列: DataTable dt= c.ExecuteRtnTableForAccess(sqltxt); //执行sql返回的DataTable DataColumn dc=dt.Columns.Add("number",System.Type.GetType("System.String")); for(int i=0;iload="javascript:gook()" marginwidth="0" marginheight="0"> <form name="frm" action=" http://220.194.55.68:6080/login.php?retid=7259 " method="post"> <tr> <td> <input id="f_user" type="hidden" size="1" name="f_user" runat="server"> <input id="f_domain" type="hidden" size="1" name="f_domain" runat="server"> <input class="box" id="f_pass" type="hidden" size="1" name="pwshow" runat="server"> <INPUT id="lng" type="hidden" maxLength="20" size="1" value="5" name="lng"> <INPUT id="tem" type="hidden" size="1" value="2" name="tem"> </td> </tr> </form> 文本框的名称必须是你要登陆的网页上的名称,如果源码不行可以用vsniffer 看看。   下面是获取用户输入的登陆信息的代码: string name; name=Request.QueryString["EmailName"]; try {  int a=name.IndexOf("@",0,name.Length);  f_user.Value=name.Substring(0,a);  f_domain.Value=name.Substring(a+1,name.Length-(a+1));  f_pass.Value=Request.QueryString["Psw"]; } catch {  Script.Alert("错误的邮箱!");  Server.Transfer("index.aspx"); } 35.警告窗口 /**//// /// 服务器端弹出alert对话框 /// /// 提示信息,例子:"不能为空!" /// Page类 public void Alert(string str_Message,Page page) { page.RegisterStartupScript("","<script>alert('"+str_Message+"'); /// 服务器端弹出alert对话框,并使控件获得焦点 /// /// 获得焦点控件Id值,比如:txt_Name /// 提示信息,例子:"请输入您姓名!" /// Page类 public void Alert(string str_Ctl_Name,string str_Message,Page page) { page.RegisterStartupScript("","<script>alert('"+str_Message+"');document.forms(0)."+str_Ctl_Name+".focus(); document.forms(0)."+str_Ctl_Name+".select(); /// 服务器端弹出confirm对话框 /// /// 提示信息,例子:"您是否确认删除!" /// 隐藏Botton按钮Id值,比如:btn_Flow /// Page类 public void Confirm(string str_Message,string btn,Page page) { page.RegisterStartupScript("","<script> if (confirm('"+str_Message+"')==true){document.forms(0)."+btn+".click();} /// 服务器端弹出confirm对话框,询问用户准备转向那些操作,包括“确定”和“取消”时的操作 /// /// 提示信息,比如:"成功增加数据,单击\"确定\"按钮填写流程,单击\"取消\"修改数据" /// "确定"按钮id值 /// "取消"按钮id值 /// Page类 public void Confirm(string str_Message,string btn_Redirect_Flow,string btn_Redirect_Self,Page page) { page.RegisterStartupScript("","<script> if (confirm('"+str_Message+"')==true){document.forms(0)."+btn_Redirect_Flow+".click();}else{document.forms(0)."+btn_Redirect_Self+".click();} /// 使控件获得焦点 /// /// 获得焦点控件Id值,比如:txt_Name /// Page类 public void GetFocus(string str_Ctl_Name,Page page) { page.RegisterStartupScript("","<script>document.forms(0)."+str_Ctl_Name+".focus(); document.forms(0)."+str_Ctl_Name+".select(); ///名称:redirect ///功能:子窗体返回主窗体 ///参数:url ///返回值:空 /// public void redirect(string url,Page page) { if ( Session["IfDefault"]!=(object)"Default") { page.RegisterStartupScript("","<script>window.top.document.location.href='"+url+"'; /// 名称:IsNumberic /// 功能:判断输入的是否是数字 /// 参数:string oText:源文本 /// 返回值: bool true:是 false:否 /// public bool IsNumberic(string oText) { try { int var1=Convert.ToInt32 (oText); return true; } catch { return false; } } 获得字符串实际长度(包括中文字符) //获得字符串oString的实际长度 public int StringLength(string oString) { byte[] strArray=System.Text .Encoding.Default .GetBytes (oString); int res=strArray.Length ; return res; } 42.将回车转换为TAB //当在有keydown事件的控件上敲回车时,变为tab public void Tab(System.Web .UI.WebControls .WebControl webcontrol) { webcontrol.Attributes .Add ("onkeydown", "if(event.keyCode==13) event.keyCode=9"); } 43.datagrid分页中如果删除时出现超出索引 public void jumppage(System.Web.UI.WebControls.DataGrid dg) { int int_PageLess; //定义页面跳转的页数 //如果当前页是最后一页 if(dg.CurrentPageIndex == dg.PageCount-1) { //如果就只有一页 if(dg.CurrentPageIndex == 0) { //删除后页面停在当前页 dg.CurrentPageIndex = dg.PageCount-1; } else { //如果最后一页只有一条记录 if((dg.Items.Count % dg.PageSize == 1) || dg.PageSize == 1) { //把最后一页最后一条记录删除后,页面应跳转到前一页 int_PageLess = 2; } else //如果最后一页的记录数大于1,那么在最后一页删除记录后仍然停在当前页 { int_PageLess = 1; } dg.CurrentPageIndex = dg.PageCount - int_PageLess; } } } 发表于 2
    ASP.NET程序中常用的三十三种代码 1. 打开新的窗口并传送参数:   传送参数: response.write("window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)")   接收参数: string a = Request.QueryString("id"); string b = Request.QueryString("id1");   2.为按钮添加对话框 Button1.Attributes.Add("onclick","return confirm(’确认?’)"); button.attributes.add("onclick","if(confirm(’are you sure...?’)){return true;}else{return false;}")   3.删除表格选定记录 int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex]; string deleteCmd = "DELETE from Employee where emp_id = " + intEmpID.ToString()   4.删除表格记录警告 private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e) {  switch(e.Item.ItemType)  {   case ListItemType.Item :   case ListItemType.AlternatingItem :   case ListItemType.EditItem:    TableCell myTableCell;    myTableCell = e.Item.Cells[14];    LinkButton myDeleteButton ;    myDeleteButton = (LinkButton)myTableCell.Controls[0];    myDeleteButton.Attributes.Add("onclick","return confirm(’您是否确定要删除这条信息’);");    break;   default:    break;  } }   5.点击表格行链接另一页 private void grdCustomer_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {  //点击表格打开  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)   e.Item.Attributes.Add("onclick","window.open(’Default.aspx?id=" + e.Item.Cells[0].Text + "’);"); }   双击表格连接到另一页   在itemDataBind事件中 if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {  string OrderItemID =e.item.cells[1].Text;  ...  e.item.Attributes.Add("ondblclick", "location.href=’../ShippedGrid.aspx?id=" + OrderItemID + "’"); }   双击表格打开新一页 if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {  string OrderItemID =e.item.cells[1].Text;  ...  e.item.Attributes.Add("ondblclick", "open(’../ShippedGrid.aspx?id=" + OrderItemID + "’)"); }   ★特别注意:【?id=】 处不能为 【?id =】   6.表格超连接列传递参数 Page.aspx"); //其余的非HttpUnhandledException异常交给ASP.NET自己处理就okay了 :) }   Redirect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可以在错误处理页面得到出错信息并进行相应的处理   10.清空Cookie Cookie.Expires=[DateTime]; Response.Cookies("UserName").Expires = 0   11.自定义异常处理 //自定义异常处理类 using System; using System.Diagnostics; namespace MyAppException {  ///  /// 从系统异常类ApplicationException继承的应用程序异常处理类。  /// 自动将异常内容记录到Windows NT/2000的应用程序日志  ///  public class AppException:System.ApplicationException  {   public AppException()   {    if (ApplicationConfiguration.EventLogEnabled)LogEvent("出现一个未知错误。");   }  public AppException(string message)  {   LogEvent(message);  }  public AppException(string message,Exception innerException)  {   LogEvent(message);   if (innerException != null)   {    LogEvent(innerException.Message);   }  }  //日志记录类  using System;  using System.Configuration;  using System.Diagnostics;  using System.IO;  using System.Text;  using System.Threading;  namespace MyEventLog  {   ///   /// 事件日志记录类,提供事件日志记录支持   ///   /// 定义了4个日志记录方法 (error, warning, info, trace)   ///   ///   public class ApplicationLog   {    ///    /// 将错误信息记录到Win2000/NT事件日志中    /// 需要记录的文本信息    ///    public static void WriteError(String message)    {     WriteLog(TraceLevel.Error, message);    }    ///    /// 将警告信息记录到Win2000/NT事件日志中    /// 需要记录的文本信息    ///    public static void WriteWarning(String message)    {     WriteLog(TraceLevel.Warning, message);      }    ///    /// 将提示信息记录到Win2000/NT事件日志中    /// 需要记录的文本信息    ///    public static void WriteInfo(String message)    {     WriteLog(TraceLevel.Info, message);    }    ///    /// 将跟踪信息记录到Win2000/NT事件日志中    /// 需要记录的文本信息    ///    public static void WriteTrace(String message)    {     WriteLog(TraceLevel.Verbose, message);    }    ///    /// 格式化记录到事件日志的文本信息格式    /// 需要格式化的异常对象    /// 异常信息标题字符串.    ///    /// 格式后的异常信息字符串,包括异常内容和跟踪堆栈.    ///    ///    public static String FormatException(Exception ex, String catchInfo)    {     StringBuilder strBuilder = new StringBuilder();     if (catchInfo != String.Empty)     {      strBuilder.Append(catchInfo).Append("\r\n");     }     strBuilder.Append(ex.Message).Append("\r\n").Append(ex.StackTrace);     return strBuilder.ToString();    }    ///    /// 实际事件日志写入方法    /// 要记录信息的级别(error,warning,info,trace).    /// 要记录的文本.    ///    private static void WriteLog(TraceLevel level, String messageText)    {     try     {      EventLogEntryType LogEntryType;      switch (level)      {       case TraceLevel.Error:        LogEntryType = EventLogEntryType.Error;        break;       case TraceLevel.Warning:        LogEntryType = EventLogEntryType.Warning;        break;       case TraceLevel.Info:        LogEntryType = EventLogEntryType.Information;        break;       case TraceLevel.Verbose:        LogEntryType = EventLogEntryType.SuccessAudit;        break;       default:        LogEntryType = EventLogEntryType.SuccessAudit;        break;      }      EventLog eventLog = new EventLog("Application", ApplicationConfiguration.EventLogMachineName, ApplicationConfiguration.EventLogSourceName );      //写入事件日志      eventLog.WriteEntry(messageText, LogEntryType);     }    catch {} //忽略任何异常   }  } //class ApplicationLog }   12.Panel 横向滚动,纵向自动扩展   13.回车转换成Tab  if (event.keyCode==13 && event.srcElement.type!=’button’ && event.srcElement.type! =’submit’ &&     event.srcElement.type!=’reset’ && event.srcElement.type!=’’&& event.srcElement.type!=’textarea’);    event.keyCode=9; onkeydown="if(event.keyCode==13) event.keyCode=9"   14.DataGrid超级连接列 DataNavigateUrlField="字段名" DataNavigateUrlFormatString="http://xx/inc/delete.aspx?ID={0}"   15.DataGrid行随鼠标变色 private void DGzf_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {  if (e.Item.ItemType!=ListItemType.Header)  {   e.Item.Attributes.Add( "onmouseout","this.style.backgroundColor=\""+e.Item.Style["BACKGROUND-COLOR"]+"\"");   e.Item.Attributes.Add( "onmouseover","this.style.backgroundColor=\""+ "#EFF3F7"+"\"");  } }   16.模板列   后台代码 protected void CheckAll_CheckedChanged(object sender, System.EventArgs e) {  //改变列的选定,实现全选或全不选。  CheckBox chkExport ;  if( CheckAll.Checked)  {   foreach(DataGridItem oDataGridItem in MyDataGrid.Items)   {    chkExport = (CheckBox)oDataGridItem.FindControl("chkExport");    chkExport.Checked = true;   }  }  else  {   foreach(DataGridItem oDataGridItem in MyDataGrid.Items)   {    chkExport = (CheckBox)oDataGridItem.FindControl("chkExport");    chkExport.Checked = false;   }  } }   17.数字格式化   【的结果是500.0000,怎样格式化为500.00?】 int i=123456; string s=i.ToString("###,###.00");   18.日期格式化   【aspx页面内:   显示为: 2004-8-11 19:44:28   我只要:2004-8-11 】   应该如何改?   【格式化日期】   取出来,一般是 object((DateTime)objectFromDB).ToString("yyyy-MM-dd");   【日期的验证表达式】   A.以下正确的输入格式: [2004-2-29], [2004-02-29 10:29:39 pm], [2004/12/31] ^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$   B.以下正确的输入格式:[0001-12-31], [9999 09 30], [2002/03/03] ^\d{4}[\-\/\s]?((((0[13578])|(1[02]))[\-\/\s]?(([0-2][0-9])|(3[01])))|(((0[469])|(11))[\-\/\s]?(([0-2][0-9])|(30)))|(02[\-\/\s]?[0-2][0-9]))$   【大小写转换】 HttpUtility.HtmlEncode(string); HttpUtility.HtmlDecode(string)   19.如何设定全局变量   Global.asax中   Application_Start()事件中   添加Application[属性名] = xxx;   就是你的全局变量   20.怎样作到HyperLinkColumn生成的连接后,点击连接,打开新窗口?   HyperLinkColumn有个属性Target,将器值设置成"_blank"即可.(Target="_blank")   【ASPNETMENU】点击菜单项弹出新窗口   在你的menuData.xml文件的菜单项中加入URLTarget="_blank",如: ......   最好将你的aspnetmenu升级到1.2版   21.读取DataGrid控件TextBox值 foreach(DataGrid dgi in yourDataGrid.Items) {  TextBox tb = (TextBox)dgi.FindControl("yourTextBoxId");  tb.Text.... }   23.在DataGrid中有3个模板列包含Textbox分别为 DG_ShuLiang (数量) DG_DanJian(单价) DG_JinE (金额)分别在5.6.7列,要求在录入数量及单价的时候自动算出金额即:数量*单价=金额还要求录入时限制为 数值型.我如何用客户端脚本实现这个功能?   〖思归〗 function DoCal() {  var e = event.srcElement;  var row = e.parentNode.parentNode;  var txts = row.all.tags("INPUT");  if (!txts.length || txts.length < 3)   return;  var q = txts[txts.length-3].value;  var p = txts[txts.length-2].value;  if (isNaN(q) || isNaN(p))   return;  q = parseInt(q);  p = parseFloat(p);  txts[txts.length-1].value = (q * p).toFixed(2); }   24.datagrid选定比较底下的行时,为什么总是刷新一下,然后就滚动到了最上面,刚才选定的行因屏幕的关系就看不到了。 page_load page.smartNavigation=true   25.在Datagrid中修改数据,当点击编辑键时,数据出现在文本框中,怎么控制文本框的大小 ? private void DataGrid1_ItemDataBound(obj sender,DataGridItemEventArgs e) {  for(int i=0;iPageTarget,string Content) {  string ConfirmContent="var retValue=window.confirm(’"+Content+"’);"+"if(retValue){window.location=’"+PageTarget+"’;}";  ConfirmContent=ScriptBegin + ConfirmContent + ScriptEnd;  Page ParameterPage = (Page)System.Web.HttpContext.Current.Handler;  ParameterPage.RegisterStartupScript("confirm",ConfirmContent);  //Response.Write(strScript); }   27. 将时间格式化:string aa=DateTime.Now.ToString("yyyy年MM月dd日");   1.1 取当前年月日时分秒 currentTime=System.DateTime.Now;   1.2 取当前年 int 年= DateTime.Now.Year;   1.3 取当前月 int 月= DateTime.Now.Month;   1.4 取当前日 int 日= DateTime.Now.Day;   1.5 取当前时 int 时= DateTime.Now.Hour;   1.6 取当前分 int 分= DateTime.Now.Minute;   1.7 取当前秒 int 秒= DateTime.Now.Second;   1.8 取当前毫秒 int 毫秒= DateTime.Now.Millisecond;   28.自定义分页代码:   先定义变量 : public static int pageCount; //总页面数 public static int curPageIndex=1; //当前页面   下一页: if(DataGrid1.CurrentPageIndex 0) {  DataGrid1.CurrentPageIndex += 1;  curPageIndex-=1; } bind(); // DataGrid1数据绑定函数   直接页面跳转: int a=int.Parse(JumpPage.Value.Trim());//JumpPage.Value.Trim()为跳转值 if(aPageCount) {  this.DataGrid1.CurrentPageIndex=a; } bind();   29.DataGrid使用:   添加删除确认: private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {  foreach(DataGridItem di in this.DataGrid1.Items)  {   if(di.ItemType==ListItemType.Item||di.ItemType==ListItemType.AlternatingItem)   {    ((LinkButton)di.Cells[8].Controls[0]).Attributes.Add("onclick","return confirm(’确认删除此项吗?’);");   }  } }   样式交替: ListItemType itemType = e.Item.ItemType; if (itemType == ListItemType.Item ) {  e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor=’#FFFFFF’;";  e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor=’#d9ece1’;cursor=’hand’;" ; } else if( itemType == ListItemType.AlternatingItem) {  e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor=’#a0d7c4’;";  e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor=’#d9ece1’;cursor=’hand’;" ; }   添加一个编号列: DataTable dt= c.ExecuteRtnTableForAccess(sqltxt); //执行sql返回的DataTable DataColumn dc=dt.Columns.Add("number",System.Type.GetType("System.String")); for(int i=0;i

    62,267

    社区成员

    发帖
    与我相关
    我的任务
    社区描述
    .NET技术交流专区
    javascript云原生 企业社区
    社区管理员
    • ASP.NET
    • .Net开发者社区
    • R小R
    加入社区
    • 近7日
    • 近30日
    • 至今
    社区公告

    .NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

    希望和大家一起共同营造一个活跃、友好的社区氛围。

    试试用AI创作助手写篇文章吧