博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
我的代码,写的pagebase。还是留着吧。语义化,与我的云平台一样,只不过云平台是用js写的。这个是webform.下回写mvc吧。核心很简单。...
阅读量:7034 次
发布时间:2019-06-28

本文共 2206 字,大约阅读时间需要 7 分钟。

Ps:记一下用的时候,一不小心我手贱碰到的问题吧: 我在页面里面加上了form runat=server,然后所有的html控件就再也找不着了。 就是下面的control collection这里,如果加上form runat=server标签,页面里面所有的控件就会变为form控件的子集。这样产生了问题,使页面不能使用,所以切忌!不要使用form runat=server标签!再不手贱了。 要么就一定要用循环的方式,把所有的控件的子集都取出来放到一个collection里面再去遍历,要么就直接用findcontrol了。一码傻三年! using System;using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using JGDJWeb.Helper; using JGDJWeb.Model; namespace JGDJWeb.Extensions { public abstract class PageBase:System.Web.UI.Page { protected PageBase() { } protected void BindModule(Page page, Action
bindSingRpt) { BindControls(page, "List_", bindSingRpt); } protected void BindControls(Page page, String prefix, Action
bindSingControl) { var controlList = page.Controls; foreach (Control control in controlList) { if (control.ID != null && control.ID.StartsWith(prefix) && control is Repeater) { var suffix = control.ID.Split('_')[1]; if (prefix == "List_") bindSingControl(control as Repeater, suffix); } } } protected void Bind(string className, HtmlAnchor anchor, Repeater repeater, int count) { try { using (var context = new JGDJEntities()) { var classNo = context.JY_News_Classs.Where(n => n.ClassCName == className).First().ClassNo; var newss = Common.GetNewsListByCNo(Encrypt.MD5Encrypt(classNo)); if (anchor != null) { anchor.HRef = "/List.aspx?ClassNo=" + Encrypt.MD5Encrypt(classNo); } repeater.DataSource = newss.Take(count); repeater.DataBind(); } } catch (Exception e) { } } #region 网站访问量 protected void pageviews() { int count = 0; //数据累加 int Stat = 0; StreamReader srd; //取得文件的实际路径 string file_path = Server.MapPath("/XML/counter.txt"); //打开文件进行读取 srd = File.OpenText(file_path); while (srd.Peek() != -1) { string str = srd.ReadLine(); count = int.Parse(str); } srd.Close(); // 在新会话启动时运行的代码 Application.Lock(); //获取Application对象中保存的网站总访问量 Stat = count; Stat += 1; object obj = Stat; Application["counter"] = obj; //将数据记录写入文件 StreamWriter srw = new StreamWriter(file_path, false); srw.WriteLine(Stat); srw.Close(); Application.UnLock(); } #endregion } }

转载于:https://www.cnblogs.com/hualiu0/p/4522699.html

你可能感兴趣的文章
世界之大,无不分层
查看>>
linux redhat5+11g
查看>>
centOS7 安装 JAVA环境
查看>>
测试博文
查看>>
Miller-Rabin随机性素数测试算法(Miller_Rabin模板)
查看>>
转eclipse failed to create the java virtual machine
查看>>
研究float的一些好文章
查看>>
我的友情链接
查看>>
TCP/IP(二) —— TCP 概述
查看>>
ROS-Indigo版在Ubuntu上的安装
查看>>
Spark for Spatial,相关资源
查看>>
oracle数据导入导出
查看>>
Flask-RESTful构建小型REST服务
查看>>
LB集群--LVS部署
查看>>
AIX磁带备份
查看>>
ELK 6.4 实时日志分析系统
查看>>
Zend Studio使用教程之在Linux上进行安装
查看>>
linux下上传本地文件至github
查看>>
Android VelocityTracker
查看>>
oracle 修改表名几种方法
查看>>