随笔分类 - ASP.NET
摘要:最普通的动态创建铵钮方法,并为此铵钮处理它的OnClick的事件。为了演示效果更佳,在aspx使用Ajax,View Code <asp:ScriptManagerID="ScriptManager1"runat="server"></asp:ScriptManager><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:PlaceHolderID="PlaceHo
阅读全文
摘要:记得以前写网站,网站上都会放一个Javascript写的实时间钟,如今网站整合有Ajax,Insus.NET也跟随改为Ajax的asp:Timer控件。使用asp:timer控件,我们需要设置一个属性Interval,设置在相对于上一次发生的 Tick 事件引发 Tick 事件之前的时间(以毫秒为单位),和一个写OnTick事件。View Code <formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server
阅读全文
摘要:为了客户要求,GridView前面10行数据显示背景色,实现方法,在GridView数据控件写一个OnRowCreated事件,<asp:GridViewID="GridView1"runat="server"OnRowCreated="GridView1_RowCreated">在.aspx.cs写:View Code protectedvoidGridView1_RowCreated(objectsender,GridViewRowEventArgse){if(e.Row.RowType==DataControlRow
阅读全文
摘要:用户控件(UserControl)写属性的写法,如类别属性写法没有两样。参考代码:InsusUserControlusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;publicpartialclassInsusUserControl:System.Web.UI.UserControl{publicstringDataKey{get{if(ViewState["DataKey"
阅读全文
摘要:你会留意到Insus.NET在前一次的写了Reset Image Size的功能http://www.cnblogs.com/insus/articles/1909037.html,这个功能是在图片显示时去做图片缩略,有网友向Insus.NET提及,这样做有点不好,就是每run一次,系统就要缩略生成一次,这样会有损性能,希望能改善一下。为了改善性能,哪只有在图片上传时或在图片管理时,实现一个功能保存一份缩略图在目录中。下面是代码(部分),请参考:View Code System.Drawing.ImageimgOriginal=System.Drawing.Image.FromFile(ori
阅读全文
摘要:asp.net有一个验证控件CustomValidator,一直没有机会使用过,今天有时间做了一个测试。如果你以前写Web站点时,常使用Javascript来做客户端验证的话,这个绝对可以使用的一个验证控件。下面Insus.NET做的例子,是让一个TextBox不能为空。在aspx写上一个TextBox 和一个Button,铵钮事件没有写什么,只是做postBack而已,另外一个就是不能少了主角asp:CustomValidator自定义验证控件。View Code <asp:TextBoxID="TextBox1"runat="server"&g
阅读全文
摘要:平常时,是因为多页共同的部分,可以开发为UserControl(用户控件),这样好维护。在网页设计时,哪一个网页需要,把用户控件拉(注册)进去即可。如:View Code 1<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>23<%@RegisterSrc="~/Header.ascx"TagName="Header"TagPref
阅读全文
摘要:或许你有做过,接过美工做好生成的Html的前台网页,开始写程序,你会知道有些简单的数据源绑定已经被美工做好了。如下:View Code <asp:DropDownListID="DropDownList1"runat="server"><asp:ListItemText="求购"></asp:ListItem><asp:ListItemText="出租"></asp:ListItem><asp:ListItemText="家政"&
阅读全文
摘要:动态产生一个TextBox控件,还要在这个文本框输入的文本是靠右对齐。protectedvoidPage_Load(objectsender,EventArgse){//new一个TextBoxTextBoxtextBox=newTextBox();//添加样式,靠右对齐textBox.Attributes.CssStyle.Add("text-align","right");//把TextBox加入至form中去this.form1.Controls.Add(textBox);}网页在run的效果:ViewSource,可以看到它产生的html,20行
阅读全文
摘要:在程序开发中,Insus.NET使用Cookie时,很少使用如http://www.cnblogs.com/insus/articles/2055310.html的写法。习惯写成Cookie集合,什么叫做Cookie集合,即是说一个Cookie,它拥有多个值。下面一系列演示,是怎样创建Cookie集合与使用。InsusBizusingSystem;usingSystem.Web;///<summary>///SummarydescriptionforInsusBiz///</summary>publicclassInsusBiz{privatestaticHttpRes
阅读全文
摘要:某些值在数据库存储为BIT,在asp.net显示时,它会显示为True或False。但实际情况之下,我们需要它显示通俗语言表达。如某种状态为开或关等。在asp.net显示,可以有好几种去显示,第一种,你可以使用CheckBox来表示状态,True将显示选中的效果,反之,是非选中的效果。而使用CheckBox也有两种情形,一种是CheckBox摆放在非Data控件模板中,直接放在网页中<asp:CheckBoxID="CheckBox1"runat="server"/>cs:this.CheckBox1.Checked=(bool)dataRo
阅读全文
摘要:在做asp.net开发时,为了存储一些信息,Insus.NET常常是Session与Cookie同时使用。Session资料在Insus.NET博客上会找到很多相关的,而Cookie相关的资料相对很少,所以想补充一下。下面是写Cookie的语法:Response.Cookies["曲奇名称"].Value="Insus.NET";读Cookie的语法:if(Request.Cookies["曲奇名称"]!=null){stringcookieValue=Request.Cookies["曲奇名称"].Value.T
阅读全文
摘要:这段时间,需要把一些C#处理的逻辑程序,搬移至SQL的存储过程中去。下面这个例子,就是怎样使用SQL的IN去替换C#的“||”参考代码,cs:View Code boolhub=false;boolstore=false;if(dataRow["Warehouse"].ToString()=="CF3"||dataRow["Warehouse"].ToString()=="CW2"){hub=true;}else{store=true;}这段代码,经Insus.NET移至SQL的存储过程之后,变为:View Cod
阅读全文
摘要:你可以参考这篇:http://www.cnblogs.com/insus/articles/2050790.htmlInsus.NET觉得它写得很不理想。因为不想写得这样复杂,或者有其它ID变化的可能,如:ContentPlaceHolderID="ContentPlaceHolder1" 有可能变为ContentPlaceHolderID="ContentPlaceHolder3",ID="TextBox1"也有可能变为ID="MemberName" 等。在目标页,得需要写判断是否存在,是否为NULL,如果不这样
阅读全文
摘要:下面这个例子是演示在MasterPage母板下面。例子始起页放一个TextBox和一个Button,并用PostBackUrl来导向目标页。如:View Code <asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server"><asp:TextBoxID="TextBox1"runat="server"></asp:TextBox><asp:Button
阅读全文
摘要:获取图片的宽度与高度,这种情形并非是在文件上传时获取,而是直接去读取图片文件来取得。可以在System.Drawing名称空间之下有一个Image类别,这个类别还有一个FromFile()方法,这样我们可以去读取图片了。.aspx.cs:View Code stringfile="Koala.jpg";//new一个Image实例,并读取图片System.Drawing.ImageinsusImage=System.Drawing.Image.FromFile(Server.MapPath(file));//实例就可以取得宽度与高度了。this.Literal1.Text=
阅读全文
摘要:今天在论坛上看到有网友有这样的需求,就是“在asp.net页面中如何点图片就在asp.net页面中堪入的SWF文件中显示这张图片”。记得Insus.NET以前也曾经实现过。既然有人也需求,那把它分享出来。下面提供的代码与方法,已经最大化简化。首先创建一个swf类别:View Code usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;///<summary>///SummarydescriptionforSwf///</summary>namespaceInsus.N
阅读全文
摘要:Server Error in '/InsusTutorials' Application. The value '5/15/2012' of the MaximumValue property of 'RangeValidator1' cannot be converted to type 'Date'.Description: An unhandled exception occurred during the execution of the current web request. Please review the st
阅读全文
摘要:再有网友问及此问题。Insus.NET重新写个简单的例子,此次把Flv Object 代码写入cs类别中。在应用时,只new它即可。Flv objFlv = new Flv();objFlv.Player();你在这里就可以看到它:View Code publicstringPlayer(){stringtexts=string.Empty;stringconfig="1:自动播放|0:连续播放|100:默认音量|0:控制栏位置|2:控制栏显示|0x000033:主体颜色|60:主体透明度|0x66ff00:光晕颜色|0xffffff:图标颜色|0xffffff:文字颜色|:logo
阅读全文
摘要:Server Error in '/Website1' Application. Must declare the scalar variable "@Author".Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
阅读全文