欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
[翻譯]你或許還為聽(tīng)說(shuō)過(guò)的一些ASP.NET 2.0要訣 - 從這里開(kāi)始出發(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 翻譯不當請指正~~畢竟我這方面的能力還是蠻欠缺的,呵呵~~

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

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

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

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

</form> 

4、容易地定位nested controls(嵌套控件?排列整齊的控件?表達不出來(lái)...呵呵~)。
在一個(gè)頁(yè)面的控件層次中查找某些控件,確實(shí)是一件很頭痛的事。但是如果你知道控件是如何嵌套(nest)的,你可以使用不怎么常用的快捷方式"$"來(lái)查找控件,而不用寫(xiě)遞歸代碼。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 屬性來(lái)給嵌套在FormView控件里面的文本框設置焦點(diǎn)。注意,用“$”來(lái)劃定嵌套方式(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ù)器端代碼中調用FindControl()方法,也有一點(diǎn)小技巧。想了解更多細節,稍后請訪(fǎng)問(wèn) 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。(使用強類(lèi)型方式訪(fǎng)問(wèn)跨頁(yè)面提交控件?)
這一條比其他任何一點(diǎn)都更加involved(包含?不像,應該是不常用的意思吧),但是十分有用。一個(gè)頁(yè)面提交信息到另一個(gè)頁(yè)面,在這里ASP.NET2.0介紹了跨頁(yè)面提交的概念。按鈕提交數據到一個(gè)頁(yè)面,把按鈕的PostBackUrl屬性設置為目標頁(yè)面的名字,就是通過(guò)這種方式(實(shí)現跨頁(yè)面提交)。
(不好意思啊,英超比賽開(kāi)始了,不得不停下來(lá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

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

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久