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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Forbes - Security
Forbes - Security
WordPress大学
WordPress大学
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
Spread Privacy
Spread Privacy
D
Darknet – Hacking Tools, Hacker News & Cyber Security
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
P
Privacy International News Feed
A
About on SuperTechFans
T
Tailwind CSS Blog
I
InfoQ
S
Securelist
云风的 BLOG
云风的 BLOG
罗磊的独立博客
Recent Announcements
Recent Announcements
T
The Exploit Database - CXSecurity.com
B
Blog RSS Feed
V
Visual Studio Blog
Know Your Adversary
Know Your Adversary
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
腾讯CDC
Cyberwarzone
Cyberwarzone
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
博客园 - 【当耐特】
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Full Disclosure
S
Secure Thoughts
博客园 - 司徒正美
J
Java Code Geeks
Y
Y Combinator Blog
Google Online Security Blog
Google Online Security Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
Help Net Security
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Project Zero
Project Zero
T
Tenable Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tor Project blog
MyScale Blog
MyScale Blog
Scott Helme
Scott Helme
小众软件
小众软件
K
Kaspersky official blog

博客园 - Caviare

前台优化法则(YSlow) ASP.NET MVC源代码 启用IIS的Gzip压缩功能 web.sitemap Dynamic Generation SQL字符正则匹配 委托应用 WorkBook操作实例 判断大陆IPAddress 迭代器和排序基本使用 Bertrand Meyer提出的设计模式的原则 - Caviare - 博客园 Web.cofig详解[转] UpdatePanel Control [转老赵博客] .Net环境下的缓存技术介绍 (转) [转]webservice和remoting在分布式程序中的应用 sql2005备份在sql2000中恢复 Excel WorkBook操作例 温故知新-Excel操作类 SQL collation设置 一张类的访问权限图,帮您加深概念
[转]您可能不知道的Asp.Net2.0技巧
Caviare · 2007-05-08 · via 博客园 - Caviare

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

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

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

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

<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>

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

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

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

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

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

7.  我们可以使用验证控件的属性      ValidationGroup 指定该验证控件所属组,同时在button的ValidationGroup属性中指定该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>

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

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

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

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

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

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

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

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