惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
K
Kaspersky official blog
Scott Helme
Scott Helme
C
CXSECURITY Database RSS Feed - CXSecurity.com
GbyAI
GbyAI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - Franky
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Y
Y Combinator Blog
T
Threat Research - Cisco Blogs
L
LINUX DO - 热门话题
C
Cyber Attacks, Cyber Crime and Cyber Security
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
月光博客
月光博客
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
人人都是产品经理
人人都是产品经理
L
Lohrmann on Cybersecurity
Recorded Future
Recorded Future
Latest news
Latest news
V2EX - 技术
V2EX - 技术
T
The Exploit Database - CXSecurity.com
H
Heimdal Security Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
IT之家
IT之家
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
AWS News Blog
AWS News Blog
H
Help Net Security
S
Security @ Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
F
Full Disclosure
S
Schneier on Security
S
Security Affairs
T
Tenable Blog

博客园 - KevinWang

Server.HtmlEncode vs HttpUtility.HtmlEncode 在FireFox IE 下Response 中文文件名乱码问题 序列化,反序列化时低序位非打印 ASCII 字符的问题 - KevinWang 月薪上万的人都懂得这些道理 c# .ToString()格式化 利用ListView和DataPager控件来对数据分页 PageMethods Not Found (or Defined)? (转) asp.net中使用ajax中的三种方式 虚方法(virtual)和抽象方法(abstract)的区别 数据库设计经验之谈(转载) 网站令浏览器崩溃的原因 各种流行的编程风格 2009年海外Web设计风潮 常用js框架,js库 硬盘RAID是什么意思?有什么用? T-SQL和PL/SQL 区别 What is PL/SQL?(PL/SQL是什么,与T-SQL对比) 数据库和数据仓库的区别 ASP.NET MVC 资料
Asp.Net2.0技巧 - KevinWang - 博客园
KevinWang · 2010-02-02 · via 博客园 - KevinWang

1. 在提交页面之后,保持滚动条的位置

可以在page指令上加上MaintainScrollPositionOnPostback指令

<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="..." Inherits="..." %>

2. 在页面载入完之后,将焦点移动到某个控件,只需要指定FormDefaultFocus属性就可以了。

<form id="frm" DefaultFocus="txtUserName" runat="server">
  ...
</form>

3. 通过DefaultButton属性设置form的默认相应按钮,即在用户敲回车时触发的按钮

<form id="frm" DefaultButton="btnSubmit" runat="server">
  ...
</form>

4. 可以使用$符号轻松的使用FindControl方法找到控件

<form id="form1" runat="server" DefaultFocus="formVw$txtName">
    <
div
>
        <
asp:FormView ID="formVw" runat
="server">
            <
ItemTemplate
>
               
Name: 
                <asp:TextBox ID="txtName" runat
="server" 
                   
Text='<%# Eval("FirstName") + " " + Eval("LastName") %>'
/>
            </
ItemTemplate
>
        </
asp:FormView
>
    </
div
>
</
form>

在上面的例子中使用formDefaultFocus属性指定页面载入时焦点所在的控件,使用$符号就可以轻松的定位txtName

也可以使用以下代码来轻松的找到控件

TextBox tb = this.FindControl("form1$formVw$txtName"as TextBox;
if 
(tb != null
)
{
    
//Access TextBox control
}

5. 关于跨页提交的取得发出提交页面控件强类型的方法,见

6. 使用强类型访问MasterPage属性成员的方法,见原文

7. 我们可以使用验证控件的属性      ValidationGroup 指定该验证控件所属组,同时在buttonValidationGroup属性中指定该button所需要激活的验证组。

<form id="form1" runat="server">
    Search Text: <asp:TextBox ID="txtSearch" runat="server" 
/> 
    <
asp:RequiredFieldValidator ID="valSearch" runat="Server"
 
      ControlToValidate
="txtSearch" ValidationGroup="SearchGroup" 
/> 
    <
asp:Button ID="btnSearch" runat="server" Text="Search"
 
      ValidationGroup
="SearchGroup" 
/>
    ....
    Other controls with validators and buttons defined here
</
form>

1.       在开发web控件时,如果控件必须放在服务器端的form内,可以通过Page.VerifyRenderingInServerForm(Control) 方法来保证。

2.       使用Control类的ResolveClientUrlstring)方法可以将类似“~/abc/ab.aspx”这样的路径转换为正确的url路径,这在.Net1.0中是一个内部方法,而在2.0中是公开的方法

3.       Button控件有两个事件,分别是OnClickOnCommand,在点击button之后这两个事件都会被触发,两者的区别是后者可以接受commanArgs参数,而前者不可以。

4.       在写Web控件时可以通过Themable特性指定某属性是否可以在Skin文件中指定值。

5.       .Net2.0的验证控件多了一个SetFocusOnError属性,可以指定发生错误的时候是否让焦点移动到要验证的控件上。

6.       Aspx页面上可以使用<%$AppSettings: settingKey%>获得配置文件appSettings配置节中指定key的值

7.       当将textbox控件的ReadOnly属性设置为true时,如果在客户端用js脚本改变了这个textbox的值,提交之后在服务器端是得不到改动后的值的,可以通过Request.Form[textbox.ClientID]获得改动後的值。

8.       .Net1.0中只有一个html input的上传文件控件,而在2.0中有了一个WebControlFileUpload,在验证用户时候选择文件并上传时,可以通过它的HasFile属性来判断,而不必这样来判断FileUpload1.PostFile != null && FileUpload1.PostFile.ContentLength > 0