国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
[翻譯]你或許還為聽說過的一些ASP.NET 2.0要訣 - 從這里開始出發(fā)....——lxinxuan‘s Blog - 博客園
原文鏈接:http://weblogs.asp.net/dwahlin/archive/2007/04/17/simple-asp-net-2-0-tips-and-tricks-that-you-may-or-may-not-have-heard-about.aspx 翻譯不當(dāng)請指正~~畢竟我這方面的能力還是蠻欠缺的,呵呵~~

在開發(fā)Web應(yīng)用程序方面,Asp.net是一個(gè)令人敬畏的框架。如果你使用過一段時(shí)間,那么這就不是什么秘密了。它提供了一些十分強(qiáng)大的新特征,而你只需要些少量的代碼就能實(shí)現(xiàn)。我曾經(jīng)列出一個(gè)清單,上面是一些你可以只用少量或不用任何c#/VB.net代碼就能實(shí)現(xiàn)的非常簡單(甚至很酷)的功能。如果你有其他建議,可以添加評論,如果你的建議是一件能夠容易應(yīng)用的任務(wù),我將進(jìn)一步更新我的清單。

1、當(dāng)頁面PostBacks的時(shí)候,保持滾動(dòng)條的位置。
在ASP.NET1.1中,當(dāng)進(jìn)行postback操作的時(shí)候,如果想保持滾動(dòng)條的位置,那真是一件痛苦的事情,特別是當(dāng)頁面上有一個(gè)grid(表格?)而你想編輯某一具體行的時(shí)候。頁面將會(huì)重新加載,滾動(dòng)條位于頁面頂端,而不是你期望的位置,這樣你就不得不下拉滾動(dòng)條。在ASP.net2.0中,你可以簡單地在Pagedirective這里加上MaintainScrollPostionOnPostBack 屬性(來實(shí)現(xiàn)同樣的功能)。
<%@ Page Language="C#" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="
" Inherits="
" %> 

2、當(dāng)頁面加載的時(shí)候,控件獲得默認(rèn)焦點(diǎn)。
這是另一件很簡單的事情,而不用通過寫javascrip腳本。如果你的頁面上只有一個(gè)(或者兩個(gè))文本輸入框,用戶為什么非要點(diǎn)擊文本框之后才能開始輸入呢?光標(biāo)難道就不能自動(dòng)位于文本框,用戶可以馬上輸入?使用HtmlForm控件的DefaultFocus 屬性,你就可以很容易地做到。
<form id="frm" DefaultFocus="txtUserName" runat="server">
  

</form> 
 
3、當(dāng)用戶按下Enter鍵的時(shí)候,設(shè)置默認(rèn)觸發(fā)按鈕。
在ASP.NET1.1中,這又是一件十分痛苦的事情。當(dāng)用戶按下Enter鍵的時(shí)候,你需要寫一些javascript代碼,來保證頁面上適當(dāng)?shù)陌粹o觸發(fā)一個(gè)服務(wù)器端“Click”事件。幸運(yùn)的是,每當(dāng)用戶按下Enter鍵的時(shí)候,你現(xiàn)在可以使用HtmlForm的DefaultButton屬性來設(shè)置點(diǎn)擊哪一個(gè)按鈕。還有一種情況,每當(dāng)user(指光標(biāo)是否更合適?)進(jìn)入頁面上不同面板觸發(fā)不同的按鈕,(這個(gè)情況下),就可以設(shè)置Panel控件的DefaultButton 屬性。
<form id="frm" DefaultButton="btnSubmit" runat="server">
  

</form> 

4、容易地定位nested controls(嵌套控件?排列整齊的控件?表達(dá)不出來...呵呵~)。
在一個(gè)頁面的控件層次中查找某些控件,確實(shí)是一件很頭痛的事。但是如果你知道控件是如何嵌套(nest)的,你可以使用不怎么常用的快捷方式"$"來查找控件,而不用寫遞歸代碼。Ifyou‘re looking for a great way to recursively find a control (in caseswhere you don‘t know the exact control nesting) check out my good buddyMichael Palermo‘s blog entry.(這一句是廣告,不翻了~)。以下代碼展示了如何使用DefaultFocus 屬性來給嵌套在FormView控件里面的文本框設(shè)置焦點(diǎn)。注意,用“$”來劃定嵌套方式(nesting):
<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>
在服務(wù)器端代碼中調(diào)用FindControl()方法,也有一點(diǎn)小技巧。想了解更多細(xì)節(jié),稍后請?jiān)L問 I blogged about this 。這里有一個(gè)例子:
TextBox tb = this.FindControl("form1$formVw$txtName") as TextBox;
if (tb != null)
{
    
//Access TextBox control


5、Strongly-typed access to cross-page postback controls。(使用強(qiáng)類型方式訪問跨頁面提交控件?)
這一條比其他任何一點(diǎn)都更加involved(包含?不像,應(yīng)該是不常用的意思吧),但是十分有用。一個(gè)頁面提交信息到另一個(gè)頁面,在這里ASP.NET2.0介紹了跨頁面提交的概念。按鈕提交數(shù)據(jù)到一個(gè)頁面,把按鈕的PostBackUrl屬性設(shè)置為目標(biāo)頁面的名字,就是通過這種方式(實(shí)現(xiàn)跨頁面提交)。
(不好意思啊,英超比賽開始了,不得不停下來看球了,剩下的內(nèi)容以原文貼出,明天再譯吧~~)
Normally,the posted data can be accessed by doing something likePreviousPage.FindControl("ControlID").  However, this requires a castif you need to access properties of the target control in the previouspage (which you normally need to do).  If you add a public propertyinto the code-behind page that initiates the postback operation, youcan access the property in a strongly-typed manner by adding thePreviousPageType directive into the target page of the postback.  Thatmay sound a little confusing if you haven‘t done it so let me explain alittle more.

If you have a page called Default.aspx that exposes a publicproperty that returns a Textbox that is defined in the page, the pagethat data is posted to (lets call it SearchResults.aspx) can accessthat property in a strongly-typed manner (no FindControl() call isnecessary) by adding the PreviousPageType directive into the top of thepage:

<%@ PreviousPageType VirtualPath="Default.aspx" %>

By adding this directive, the code in SearchResults.aspx can accessthe TextBox defined in Default.aspx in a strongly-typed manner.  Thefollowing example assumes the property defined in Default.aspx is namedSearchTextBox.

TextBox tb PreviousPage.SearchTextBox;

This code obviously only works if the previous page isDefault.aspx.  PreviousPageType also has a TypeName property as wellwhere you could define a base type that one or more pages derive fromto make this technique work with multiple pages.  You can learn more about PreviousPageType here.

6. Strongly-typed access to Master Pages controls:The PreviousPageType directive isn‘t the only one that providesstrongly-typed access to controls.  If you have public propertiesdefined in a Master Page that you‘d like to access in a strongly-typedmanner you can add the MasterType directive into a page as shown next(note that the MasterType directive also allows a TypeName to bedefined as with the PreviousPageType directive):

<%@ MasterType VirtualPath="MasterPage.master" %>

You can then access properties in the target master page from a content page by writing code like the following:

this.Master.HeaderText "Label updated using MasterType directive with VirtualPath attribute.";

You can find several other tips and tricks related to working withmaster pages including sharing master pages across IIS virtualdirectories at a previous blog post I wrote

7. Validation groups: You may have a page that hasmultiple controls and multiple buttons.  When one of the buttons isclicked you want specific validator controls to be evaluated ratherthan all of the validators defined on the page.  With ASP.NET 1.1 therewasn‘t a great way to handle this without resorting to some hack code. ASP.NET 2.0 adds a ValidationGroup property to all validator controlsand buttons (Button, LinkButton, etc.) that easily solves theproblem.  If you have a TextBox at the top of a page that has aRequiredFieldValidator next to it and a Button control, you can firethat one validator when the button is clicked by setting theValidationGroup property on the button and on theRequiredFieldValidator to the same value.  Any other validators not inthe defined ValidationGroup will be ignored when the button is clicked.Here‘s an example:

<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. Finding control/variable names while typing code: This tip is a bit more related to VS.NET than to ASP.NET directly, butit‘s definitely helpful for those of you who remember the first fewcharacters of control variable name (or any variable for that matter)but can‘t remember the complete name.  It also gives me the chance tomention two great downloads from Microsoft.  First the tip though. After typing the first few characters of a control/variable name, hitCTRL + SPACEBAR and VS.NET will bring up a short list of matchingitems.  Definitely a lot easier than searching for the control/variabledefinition.  Thanks to Darryl for the tip.  For those who areinterested, Microsoft made all of the VS.NET keyboard shortcutsavailable in a nice downloadable and printable guide.  Get the C# version here and the VB.NET version here.

That‘s all for now.  There are a lot of other things that could bementioned and I‘ll try to keep this post updated.  Have agreat (simple) ASP.NET 2.0 tip or trick?  Post the details in thecomments and I‘ll add it if the content is appropriate for the list. Make sure to list your name so I can give proper credit.

For those who are interested, you can also view videos I‘ve puttogether that show how to accomplish different tasks from working withAJAX, to ASP.NET to Web Services and WCF at the following URL:

http://weblogs.asp.net/dwahlin/archive/tags/Video/default.aspx

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
使用Cross-Page Postback 頁面間傳值
使用Asp.net動(dòng)態(tài)生成控件的使用總結(jié)! - 秋風(fēng)夜狼 - sweet_chenqian...
實(shí)現(xiàn)無刷新DropDownList聯(lián)動(dòng)效果
ASP.NET頁面?zhèn)髦档姆椒ê鸵恍?shí)用技巧
ASP.NET Web 頁面語法概覽
.NET中獲取服務(wù)器端控件的ID進(jìn)行客戶端編程
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服