有时候在项目中需要根据实际传过来的参数来生成不同个数的控件来摆放在页面上,这时候可以重写页面 Render方法来达到目的。
下面提供一个示例来实现,代码如下:
//生成要重写的html代码
private string createInputItem()
{
if (Session["Count"] != null)
{
int icount = int.Parse(Session["Count"].ToString());
StringBuilder sbHtml = new StringBuilder();
#region Input Value
for (int i = 1; i <= icount; i++)
{
sbHtml.Append("<tr align=\"left\"> ");
sbHtml.Append("<td style=\"width:150px\" align=\"left\">");
sbHtml.Append("Schacht " + i.ToString() + " SPN F001 ");
sbHtml.Append("</td> ");
sbHtml.Append("<td style=\"width:80px\" align=\"left\">");
sbHtml.Append("<input name=\"txtSPNF001_" + i.ToString() + "\" type=\"text\" style=\"width:80px\" />");
sbHtml.Append("</td> ");
sbHtml.Append("<td style=\"width:30px\" align=\"left\">");
sbHtml.Append("øC");
sbHtml.Append("</td>");
sbHtml.Append("</tr>");
sbHtml.Append("<tr align=\"left\"> ");
sbHtml.Append("<td style=\"width:150px\" align=\"left\">");
sbHtml.Append("Schacht " + i.ToString() + " T001");
sbHtml.Append("</td> ");
sbHtml.Append("<td style=\"width:80px\" align=\"left\">");
sbHtml.Append("<input name=\"txtT001_" + i.ToString() + "\" type=\"text\" style=\"width:80px\" />");
sbHtml.Append("</td> ");
sbHtml.Append("<td style=\"width:30px\" align=\"left\">");
sbHtml.Append("øC");
sbHtml.Append("</td>");
sbHtml.Append("</tr>");
sbHtml.Append("<tr align=\"left\"> ");
sbHtml.Append("<td style=\"width:150px\" align=\"left\">");
sbHtml.Append("Schacht " + i.ToString() + " T007,T009");
sbHtml.Append("</td> ");
sbHtml.Append("<td style=\"width:80px\" align=\"left\">");
sbHtml.Append("<input name=\"txtT007_T009_" + i.ToString() + "\" type=\"text\" style=\"width:80px\" />");
sbHtml.Append("</td> ");
sbHtml.Append("<td style=\"width:30px\" align=\"left\">");
sbHtml.Append("øC");
sbHtml.Append("</td>");
sbHtml.Append("</tr>");
sbHtml.Append("<tr align=\"left\"> ");
sbHtml.Append("<td style=\"width:150px\" align=\"left\">");
sbHtml.Append("Schacht " + i.ToString() + " VM");
sbHtml.Append("</td> ");
sbHtml.Append("<td style=\"width:80px\" align=\"left\">");
sbHtml.Append("<input name=\"txtVM_" + i.ToString() + "\" type=\"text\" style=\"width:80px\" />");
sbHtml.Append("</td> ");
sbHtml.Append("<td style=\"width:30px\" align=\"left\">");
sbHtml.Append("øC");
sbHtml.Append("</td>");
sbHtml.Append("</tr>");
}
#endregion
return sbHtml.ToString();
}
return string.Empty;
}
protected override void Render(HtmlTextWriter writer)
{
StringWriter sw = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
base.Render(htmlWriter);
string strTableTR = createInputItem();
string html = sw.ToString() ;
//将刚才生成的Html代码插入到页面中
int startPoint = html.IndexOf("</table>", StringComparison.CurrentCultureIgnoreCase);
if(startPoint > 0)
{
html = html.Insert(startPoint, strTableTR);
}
writer.Write(html);
}
分享到:
相关推荐
代码隐藏页模型与单文件页模型不同的是,代码隐藏页模型将事物处理代码都存放在cs文件中,当ASP.NET网页运行的时候,ASP.NET类生成时会先处理cs文件中的代码,再处理.aspx页面中的代码。这种过程被成为代码分离。 ...
ComponentOne Studio for ASP.NET Wijmo 2012 v3 1/5 一共有 5 个压缩文件,请全部下载后解压 ComponentOne ASP.NET Wijmo 2012 v3 The Ultimate UI Tools for ASP.NET WebForms & MVC Do more with less code. ...
当用GridView导出Execl的时候,会发生只能在执行 Render() 的过程中调用 RegisterForEventValidation的错误提示。 有两种方法可以解决以上问题: 1.修改web.config(不推荐)<pages enableEventValidation ="false" >...
3.8.10 在render方法中利用基类资源 57 3.8.11 条件编译&条件属性 60 3.9 本章总结 61 第4章 服务器控件属性 62 4.1 控件属性的作用 62 4.1.1 系统属性 62 4.1.2 自定义属性 62 4.2 简单属性 63 4.3 属性的...
以前曾说过用HttpModule来在Response前更改Cookie,今天遇到Asp.net自做主张,把我辛苦转换的汉字ꪻ这样的表现形式,又转成汉字,别说是Asp.net的Web控件,就是Html控件Ranat=server都会被它强行转换成汉字输出。...
ASP.NET MVC 2 Release Candidate Release Notes This document describes the Release Candidate release of the ASP.NET MVC 2 framework. Installation Notes 2 Documentation 2 Support 2 Upgrading an ASP...
(一).概述... (二).应用场景代码示例......1).ScriptManager控件示例...... 1.... 2. 捕获Ajax异步调用中错误(默认使用alert提示).... 在客户端调用页面后台(Page behind)中方法示例... 8). 在客户端调用W
通过调用一个方法来生成,而这个方法是通过render方法的参数传递给他的; 通过这三个参数,可以生成一个完整的模板 官网实例 //未使用render函数 Vue.component('anchored-heading', { template: '#anchored-...
ComponentOne Studio for ASP.NET Wijmo 2012 v3 1/5 一共有 5 个压缩文件,请全部下载后解压 ComponentOne ASP.NET Wijmo 2012 v3 The Ultimate UI Tools for ASP.NET WebForms & MVC Do more with less code. ...
ComponentOne Studio for ASP.NET Wijmo 2012 v3 1/5 一共有 5 个压缩文件,请全部下载后解压 ComponentOne ASP.NET Wijmo 2012 v3 The Ultimate UI Tools for ASP.NET WebForms & MVC Do more with less code. ...
ComponentOne Studio for ASP.NET Wijmo 2012 v3 1/5 一共有 5 个压缩文件,请全部下载后解压 ComponentOne ASP.NET Wijmo 2012 v3 The Ultimate UI Tools for ASP.NET WebForms & MVC Do more with less code. ...
ComponentOne Studio for ASP.NET Wijmo 2012 v3 1/5 一共有 5 个压缩文件,请全部下载后解压 ComponentOne ASP.NET Wijmo 2012 v3 The Ultimate UI Tools for ASP.NET WebForms & MVC Do more with less code. ...
vue+render 实现 动态加载组件 后面会用来做运营活动模板组件
我们知道,无论是ASP.NET1.x,2.0,甚至是以后的版本,ASP.NET最终Render到Client端通过浏览器浏览的都是一样:一个单纯的HTML。Client通过Submit Form的方式将填入Form的数据提交给Server进行处理。我们现在来看看...
对大部分使用asp.net技术开发两年左右的开发人员来说,本书75%以上的内容可能没有接触过,本书将通过笔者精心准备的一些生动的例子来阐述这些内容。. 本书适合从事asp.net技术多年想往深度理解asp.net工作机制的...
ComponentOne Studio for ASP.NET Wijmo 2013 v1 3/5 共五个压缩文件,请全部下载后解压 Part of: Ultimate | Enterprise 40+ styled, supercharged, and easy-to-use controls built on Web standards including...
ComponentOne Studio for ASP.NET Wijmo 2013 v1 5/5 共五个压缩文件,请全部下载后解压 Part of: Ultimate | Enterprise 40+ styled, supercharged, and easy-to-use controls built on Web standards including...
ComponentOne Studio for ASP.NET Wijmo 2013 v1 2/5 共五个压缩文件,请全部下载后解压 Part of: Ultimate | Enterprise 40+ styled, supercharged, and easy-to-use controls built on Web standards including...
ComponentOne Studio for ASP.NET Wijmo 2013 v1 4/5 共五个压缩文件,请全部下载后解压 Part of: Ultimate | Enterprise 40+ styled, supercharged, and easy-to-use controls built on Web standards including...
ComponentOne Studio for ASP.NET Wijmo 2013 v1 1/5 共五个压缩文件,请全部下载后解压 Part of: Ultimate | Enterprise 40+ styled, supercharged, and easy-to-use controls built on Web standards including...