木子屋 Dnawo's BLOG

分类:Web编程

共 938 篇

ASP.NET页面Form嵌套解决方法

Default.aspx: 客户端代码: form1是ASP.NET自带的,由于它的存在,form2无法正常提交,点击submit按钮,表单将提交到Default.aspx页面(form3,form4能正常提交),解决方法如下:

C#解析"a=1&b=2&c=3"字符串

若该字符串是使用Http Get发送,url?a=1&b=2&c=3,使用下边代码即可获取参数a的值: 若该字符串是远程接口返回,以前都是用Split函数去拆分,今天发现一个非常强大的方法ParseQueryString,简单多了:

Repeater一行多列示例

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> int RepeatColumns = 3; //每行列数 int TotalColumns = 0;…

ASP.NET多层结构不用非默认构造函数创建实体对象

在ASP.NET多层结构中,我们可能调用非默认构造函数来创建并初始化一个实体对象,他很便捷,下边是添加用户的例子: 类似的语句在站点中可能还有很多,好了,当某天我们在表中增加一个字段并生成新的实体类时,错误来了: “UserInfo”不包含采用“2”个参数的构造函数 所以,建议调用默认构造函数创建实体对象,再手工对其初始化,虽麻烦了点,反而更好:

ASP.NET:使用CompareValidator控件注意事项

在ASP.NET2.0中,CompareValidator控件用来验证两个输入控件中的内容是否一样,与之对应有两个属性ControlToCompare和ControlToValidate,用来设置要比较的两个输入控件的名称,按理说比较应该不分先后,两个属性的设置应该没什么讲究,但实际并非如此,看下边代码: 测试结果:当txtUsp2值为空时CompareValidator控件不会发生作用,经多次测试,确切的说是ControlToValidate属性对应的输入控件值为空时CompareValidator控件不发生作用。 所以,CompareValidator控件也应该要RequiredFieldValidator控件配合一块使用,并且RequiredFieldValidator控件应放在ControlToValidate属性对应的输入控件上使用。示例代码:

FCKeditor.Net_2.6.4安装和使用

1.下载FCKeditor FCKeditor.Net下载:http://sourceforge.net/projects/fckeditor/files/FCKeditor.Net/2.6.4/ FCKeditor下载:http://sourceforge.net/projects/fckeditor/files/FCKeditor/2.6.4/ 说明:FCKeditor.Net中不包含主要文件,所以仍然需要下载FCKeditor,这在官方站点中有说明。 The main code is not included in this package, just the ASP.Net Control. You still need the FCKeditor scripts to be able to run it, so download it too.…

ASP.NET:TextBox为空时RegularExpressionValidator控件不起作用

上边代码中,当TextBox1内容不为空时,点击按钮后RegularExpressionValidator控件能起到验证作用;当TextBox1内容为空时,点击按钮后页面竟成功提交了,RegularExpressionValidator失效了。查了下MSDN,有如下说明: 如果输入控件为空,则表明验证成功。如果相关输入控件需要一个值,则除了使用 RegularExpressionValidator 控件外,还须使用 RequiredFieldValidator 控件。 所以,上边现象是正常的,觉得奇怪只是对RegularExpressionValidator控件不了解罢了。 参考资料 RegularExpressionValidator 类:http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.regularexpressionvalidator(v=VS.80).aspx

C#遍历二维数组

using System; namespace ConsoleApplication1 { class Program { public static void Main(string args) { int ids = new int { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }; for (int i = 0; i < ids.GetLength(0); i++) { for (int j = 0; j < ids.GetLength(1); j++) { Console.…