{"id":274,"date":"2007-04-09T09:41:56","date_gmt":"2007-04-09T01:41:56","guid":{"rendered":"http:\/\/www.jason695.idv.tw:81\/wordpress\/?p=274"},"modified":"2007-04-09T09:41:56","modified_gmt":"2007-04-09T01:41:56","slug":"%e8%bd%89%e8%b2%bc%e8%a8%ad%e8%a8%88aspnet%e6%87%89%e7%94%a8%e7%a8%8b%e5%ba%8f%e7%9a%84%e4%b8%83%e5%a4%a7%e7%b5%95%e6%8b%9b","status":"publish","type":"post","link":"https:\/\/jason695.why3s.tw\/wordpress\/2007\/04\/09\/%e8%bd%89%e8%b2%bc%e8%a8%ad%e8%a8%88aspnet%e6%87%89%e7%94%a8%e7%a8%8b%e5%ba%8f%e7%9a%84%e4%b8%83%e5%a4%a7%e7%b5%95%e6%8b%9b\/","title":{"rendered":"[\u8f49\u8cbc]\u8a2d\u8a08ASP.NET\u61c9\u7528\u7a0b\u5e8f\u7684\u4e03\u5927\u7d55\u62db"},"content":{"rendered":"<p>\u96a8\u8457\u5fae\u8edf.NET\u7684\u6d41\u884c\uff0cASP.NET\u8d8a\u4f86\u8d8a\u70ba\u5ee3\u5927\u958b\u767c\u4eba\u54e1\u6240\u63a5\u53d7\u3002\u4f5c\u70baASP.NET\u7684\u958b\u767c\u4eba\u54e1\uff0c\u6211\u5011\u4e0d\u50c5\u9700\u8981\u638c\u63e1\u5176\u57fa\u672c\u7684\u539f\u7406\uff0c\u66f4\u8981\u591a\u591a\u5be6\u8e10\uff0c\u5f9e\u5be6 \u8e10\u4e2d\u7372\u53d6\u771f\u6b63\u7684\u958b\u767c\u672c\u9818\u3002\u5728\u6211\u5011\u7684\u5be6\u969b\u958b\u767c\u4e2d\uff0c\u5f80\u5f80\u57fa\u672c\u7684\u539f\u7406\u6eff\u8db3\u4e0d\u4e86\u958b\u767c\u9700\u6c42\uff0c\u6211\u5011\u66f4\u591a\u7684\u8981\u7a4d\u7d2f\u4e00\u4e9b\u958b\u767c\u6280\u5de7\uff0c\u672c\u6587\u5c31\u5411\u5927\u5bb6\u4ecb\u7d39\u4e00\u4e9b\u5be6\u7528\u6280\u5de7\uff0c\u5e0c\u671b\u5c0d\u5927 \u5bb6\u7684\u958b\u767c\u6709\u6240\u88e8\u76ca\u3002<\/p>\n<p><strong>1. ~ \u7684\u7528\u6cd5<\/strong><br \/>\n\u4e00 \u822c\u7684\u60c5\u6cc1\u4e0b\uff0c\u6211\u5011\u662f\u4f7f\u7528.\/..\/ \u9019\u6a23\u7684\u76f8\u5c0d\u8def\u5f91\u4f86\u78ba\u5b9a\u548c\u898f\u5283\u6211\u5011\u7684\u8cc7\u6e90(\u6bd4\u5982\u5716\u7247\u3001\u8cc7\u6e90\u6587\u4ef6)\uff0c\u4f46\u9019\u7a2e\u65b9\u5f0f\u4e0b\u5728\u6211\u5011\u90e8\u7f72\u61c9\u7528\u7684\u6642\u5019\uff0c\u53ef\u80fd\u6703\u51fa\u932f\uff0c\u53e6\u5916\u5c0d\u65bc.ascx\u7684\u63a7\u4ef6\u4e2d\u5982\u679c\u5305\u542b\u4e86\u4e00 \u500b\u5716\u7247\uff0c\u800c\u9019\u500b\u63a7\u4ef6\u88ab\u6211\u5011\u5728\u4e0d\u540c\u5c64\u6b21\u7684\u5169\u500b\u76ee\u9304\u7684aspx\u6587\u4ef6\u5206\u5225\u5f15\u7528\u6642\uff0c\u554f\u984c\u5c31\u6703\u51fa\u73fe\u4e86\u3002<br \/>\n~\/image\/about.bmp \u662f\u4e00\u7a2e\u975e\u5e38\u597d\u7684\u65b9\u6cd5\uff0c\u5b83\u4ee5Web\u61c9\u7528\u7a0b\u5e8f\u7684\u6839\u76ee\u9304\u70ba\u8d77\u59cb\u9ede\uff0c\u9019\u6a23\u4f7f\u5f97\u6bd4\u4f60\u4f7f\u7528.\/image\/about.bmp\u9019\u6a23\u7684\u65b9\u5f0f\u8981\u66f4\u52a0\u9748\u6d3b\u548c\u65b9\u4fbf\u3002\u6709\u4e00\u9ede\u4e0d \u597d\uff0c\u662f\u9019\u7a2e\u65b9\u5f0f\u662f\u5728ASP.NET\u904b\u884c\u6642\u52d5\u614b\u89e3\u6790\u7684\uff0c\u6240\u4ee5\u5728IDE\u8a2d\u8a08\u6a21\u5f0f\u4e2d\uff0c\u4f60\u53ef\u80fd\u4e0d\u80fd\u9810\u89bd\u5b83\u3002<\/p>\n<p><strong>2. \u5728\u5237\u65b0\u548c\u63d0\u4ea4\u9801\u9762\u5f8c\uff0c\u4fdd\u5b58\u4f60\u7684\u9801\u9762\u6efe\u52d5\u689d\u7684\u4f4d\u7f6e<\/strong><br \/>\n\u7d93 \u5e38\u6709\u9019\u6a23\u7684\u60c5\u6cc1\uff0c\u6211\u5011\u9700\u8981\u7528\u6236\u63d0\u4ea4\u4e00\u500b\u8868\u55ae\uff0c\u4f46\u662f\u8868\u55ae\u4e2d\u6709\u8d85\u904e500+\u500b?\u63a7\u4ef6\u6216\u6587\u672c\u6846\u8981\u586b\u5beb\uff0c\u4e5f\u5c31\u662f\u8aaa\u7528\u6236\u9700\u8981\u62c9\u52d5IE\u7684\u6efe\u52d5\u689d\u624d\u80fd\u5920\u586b\u5f97\u5b8c\uff0c\u90a3\u9ebc\u5047\u5982 \u7528\u6236\u6b63\u5728\u53ef\u898bIE\u7bc4\u570d\u76842\/3\u8655\uff0c\u9078\u64c7\u4e86\u4e00\u500b\u7d44\u5408\u6846\u7684\u503c\uff0c\u5f88\u4e0d\u5e78\u7d44\u5408\u6846\u662f\u670d\u52d9\u5668\u7aef\u7684\uff0c\u90a3\u9ebc\u4e5f\u5c31\u610f\u5473\u8457\u9801\u9762\u6703\u63d0\u4ea4\u4e00\u6b21\uff0c\u800c\u7576\u7528\u6236\u518d\u770b\u898b\u5237\u65b0\u904e\u7684\u9801\u9762\u6642\uff0c\u9801\u9762 \u78ba\u5b9a\u57283\/1\u7684\u5730\u65b9\u4e5f\u5c31\u662f\u986f\u793a\u5728\u9801\u9762\u6700\u958b\u59cb\u7684\u5730\u65b9\uff0c\u7528\u6236\u53ea\u6709\u62d6\u52d5\u9f20\u6a19\uff0c\u7136\u5f8c\u63a5\u8457\u525b\u525b\u7684\u5730\u65b9\u518d\u586b\u5beb\u5269\u4e0b\u7684250\u500b\u63a7\u4ef6\uff0c\u5f88\u4e0d\u5e78\uff0c370\u500b\u63a7\u4ef6\u53c8\u9700\u8981\u4ed6\u9078\u64c7\u4e00 \u4e0b?<br \/>\n\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\u53ef\u4ee5\u5f88\u5feb\u5730\u78ba\u5b9a\u548c\u8a18\u4f4f\u4f60\u63d0\u4ea4\u524d\u7684\u4f4d\u7f6e\u3002<br \/>\n\u7db2\u4e0a\u7684Old Dog Learns New Tricks\u4e5f\u6709\u4e00\u500b\u985e\u4f3c\u7684\u4f8b\u5b50Maintain Scroll Position in any Page Element\uff0c\u4e0d\u904e\u4ed6\u4f7f\u7528\u4e86Web Behavior\u9019\u610f\u5473\u8457\u4f60\u9700\u8981\u4f7f\u7528\u4e00\u500b.htc\u6587\u4ef6<br \/>\nPrivate Sub RetainScrollPosition()<br \/>\nDim saveScrollPosition As New StringBuilder<br \/>\nDim setScrollPosition As New StringBuilder<br \/>\nRegisterHiddenField(&#8220;__SCROLLPOS&#8221;, &#8220;0&#8221;)<br \/>\nsaveScrollPosition.Append(&#8220;\uff1cscript language=&#8217;javascript&#8217;\uff1e&#8221;)<br \/>\nsaveScrollPosition.Append(&#8220;function saveScrollPosition() {&#8220;)<br \/>\nsaveScrollPosition.Append(&#8221; document.forms[0].__SCROLLPOS.value = thebody.scrollTop;&#8221;)<br \/>\nsaveScrollPosition.Append(&#8220;}&#8221;)<br \/>\nsaveScrollPosition.Append(&#8220;thebody.onscroll=saveScrollPosition;&#8221;)<br \/>\nsaveScrollPosition.Append(&#8220;\uff1c\/script\uff1e&#8221;)<br \/>\nRegisterStartupScript(&#8220;saveScroll&#8221;, saveScrollPosition.ToString())<br \/>\nIf (Page.IsPostBack = True) Then<br \/>\nsetScrollPosition.Append(&#8220;\uff1cscript language=&#8217;javascript&#8217;\uff1e&#8221;)<br \/>\nsetScrollPosition.Append(&#8220;function setScrollPosition() {&#8220;)<br \/>\nsetScrollPosition.Append(&#8221; thebody.scrollTop = &#8221; &amp; Request(&#8220;__SCROLLPOS&#8221;) &amp; &#8220;;&#8221;)<br \/>\nsetScrollPosition.Append(&#8220;}&#8221;)<br \/>\nsetScrollPosition.Append(&#8220;thebody.onload=setScrollPosition;&#8221;)<br \/>\nsetScrollPosition.Append(&#8220;\uff1c\/script\uff1e&#8221;)<br \/>\nRegisterStartupScript(&#8220;setScroll&#8221;, setScrollPosition.ToString())<br \/>\nEnd If<br \/>\nEnd Sub<br \/>\nPrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br \/>\nRetainScrollPosition()<br \/>\nEnd Sub<\/p>\n<p><strong>3. DataList\u4f7f\u7528\u4e0d\u540c\u98a8\u683c\u7684\u6a21\u677f<\/strong><br \/>\n\u9019\u62db\u4e5f\u975e\u5e38\u5be6\u7528\uff0c\u4f60\u53ef\u4ee5\u88fd\u4f5c\u5169\u500b\u4e0d\u540c\u7684\u6a21\u677f\u6216\u8868\u73fe\u5f62\u5f0f\uff0c\u5206\u5225\u4ee5.ascx\u63a7\u4ef6\u7684\u5f62\u5f0f\u4fdd\u5b58\uff0c\u904b\u884c\u6642\u6839\u64da\u67d0\u500b\u689d\u4ef6\u52d5\u614b\u7684\u9078\u64c7\u4f7f\u7528\u5176\u4e2d\u7684\u4e00\u500b\u6a21\u677f\uff0c\u53e6\u5916ScottGu\u8a8d\u70baItemDataBound\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u5b9a\u5236\u4f60\u986f\u793a\u7684\u8868\u73fe\uff0c\u6bd4\u5982\u52a0\u4eae\u67d0\u500b\u5143\u7d20\u6216\u662f\u52a0\u4e00\u500b\u4fc3\u92b7\u5ee3\u544a\u5716\u7b49\u7b49\u3002<br \/>\nDim theme As String<br \/>\ntheme = DropDownList1.SelectedValue<br \/>\nDataList1.ItemTemplate = Page.LoadTemplate(theme &amp; &#8220;.ascx&#8221;) &#8212;Cool<br \/>\nDataList1.DataSource = DS<br \/>\nDataList1.DataBind()<\/p>\n<p><strong>4. \u8a2d\u7f6e\u670d\u52d9\u5668\u7aef\u63a7\u4ef6\u7684\u7126\u9ede<\/strong><br \/>\nPrivate Sub SetFocus(ByVal controlToFocus As Control)<br \/>\nDim scriptFunction As New StringBuilder<br \/>\nDim scriptClientId As String<br \/>\nscriptClientId = controlToFocus.ClientID<br \/>\nscriptFunction.Append(&#8220;\uff1cscript language=&#8217;javascript&#8217;\uff1e&#8221;)<br \/>\nscriptFunction.Append(&#8220;document.getElementById(&#8216;&#8221; &amp; scriptClientId &amp; &#8220;&#8216;).focus();&#8221;)<br \/>\nscriptFunction.Append(&#8220;\uff1c\/script\uff1e&#8221;)<br \/>\nRegisterStartupScript(&#8220;focus&#8221;, scriptFunction.ToString())<br \/>\nEnd Sub<br \/>\nPrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br \/>\nIf (Page.IsPostBack = False) Then<br \/>\nSetFocus(TextBox1)<br \/>\nEnd If<br \/>\nEnd Sub<\/p>\n<p><strong>5. \u6efe\u52d5DataGrid<\/strong><br \/>\n\u9019\u62db\u5c31\u66f4\u7c21\u55ae\u4e86\uff0c\u6709\u6642\u5019\u4f60\u7684\u9801\u9762\u53ea\u6709\u4e00\u500b\u56fa\u5b9a\u7684\u5730\u65b9\uff0c\u4f46\u662f\u9700\u8981\u986f\u793a\u975e\u5e38\u591a\u7684\u6578\u64da\uff0c\u4ea6\u6216\u662f\u4e5f\u4e0d\u5b9a\uff0c\u4f46\u662f\u53ea\u6709\u56fa\u5b9a\u7684\u4e00\u500b\u5730\u65b9\u7d66\u4f60\u986f\u793a\u5b83\u4e86\u3002\u9019\u6642\u4f60\u5c31\u53ef\u4ee5\u7528\u4e0b\u9762\u9019\u62db\uff0c\u81ea\u52d5\u51fa\u6efe\u52d5\u689d\uff0c\u800c\u4e14\u9069\u7528\u8a31\u591a\u63a7\u4ef6\u3002\u5f88\u7c21\u55ae\u5c07\u4f60\u7684\u63a7\u4ef6\u653e\u5728\u4e00\u500bDIV\u4e2d\u5c07overflow\u5c6c\u6027\u8a2d\u7f6e\u6210auto<br \/>\n\uff1cdiv style=\u300cheight:400px;width:200px;overflow:auto\u300d\uff1e<br \/>\n\uff1casp:datagrid id=\u300cMyGrid\u300d runat=\u300cserver\u300d\/\uff1e<br \/>\n\uff1c\/div\uff1e<\/p>\n<p><strong>6. \u52d5\u614b\u5275\u5efa\u63a7\u4ef6<\/strong><br \/>\n\u5229\u7528PlaceHolder\u63a7\u4ef6\uff0c\u9019\u6771\u897f\u5728ASP.NET 2.0 Mutil-View\u548cMaster Page\u4e2d\u904b\u7528\u7684\u5c31\u66f4\u52a0\u591a\u4e86\u3002<br \/>\nSub Page_Load()<br \/>\nDim i as Integer<br \/>\nFor i=0 to 4<br \/>\nDim myUserControl as Control<br \/>\nmyUserControl = Page.LoadControl(\u300cfoo.ascx\u300d)<br \/>\nPlaceHolder1.Controls.Add(myUserControl)<br \/>\nPlaceHolder1.Controls.Add(New LiteralControl(\u300c\uff1cbr\uff1e\u300d))<br \/>\nNext i<br \/>\nEnd Sub<\/p>\n<p><strong>7. \u5ba2\u6236\u7aef\u4ee3\u78bc\u7684\u4f7f\u7528<\/strong><br \/>\n1). \u53ef\u4ee5\u4f7f\u7528\u5ba2\u6236\u7aef\u7684\u4e8b\u4ef6\u4ee3\u78bc\uff0c\u4f46\u5169\u8005\u4e0d\u80fd\u540c\u540d\uff0c\u670d\u52d9\u5668\u7aef\u4ee3\u78bc\u7684\u540d\u662f\u4f60\u53ef\u4ee5\u63a7\u5236\u7684\u3002\u5c0d\u65bc\u975eASP.NET\u7684\u6a19\u6e96\u63a7\u4ef6\u7684\u81ea\u5b9a\u7fa9\u63a7\u4ef6\u5fc5\u9808\u5be6\u73feIAttributeAccessor\u63a5\u53e3\u6216\u5f9eWebControl\u6d3e\u751f\u4e26\u4e14\u53ef\u7528expando\u5c6c\u6027<br \/>\nasp:ImageButton id=\u300cfoo\u300d<br \/>\nImageUrl=\u300cstart.jpg\u300d<br \/>\nonMouseOver=\u300crollover(this);\u300d<br \/>\nonMouseOut=\u300crollout(this)\u300d<br \/>\nrolloversrc=&#8221;\/Files\/BeyondPic\/2005-11\/12\/0511120747085590.jpg&#8221;\u300d<br \/>\nrunat=\u300cserver\u300d\/\uff1e<br \/>\n\uff1cinput type=Button onClick=\u300creturn clientHandler()\u300d<br \/>\nonServerClick=\u300cButton1_Click\u300d \u2026 \/\uff1e<\/p>\n<p>2). \u4f7f\u7528\u53ef\u4ee5\u5728Postback\u4e4b\u524d\u57f7\u884c\u5ba2\u6236\u7aef\u4ee3\u78bc\uff0c\u7576\u7136\u4e5f\u53ef\u4ee5\u53d6\u6d88\u9019\u6b21Postback\uff0c\u53e6\u5916\u4e5f\u53ef\u4ee5\u8a2a\u554f\u5ba2\u6236\u7aef\u8a72\u9801\u6240\u6709\u7684\u5ba2\u6236\u7aef\u63a7\u4ef6\u3002<br \/>\nPrivate Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) \u3000Handles MyBase.Load<br \/>\nRegisterOnSubmitStatement(&#8220;foo&#8221;, &#8220;return confirm(&#8216;Are you sure you want to submit the order?&#8217;);&#8221;)<br \/>\nEnd Sub<\/p>\n<p>3). \u9084\u6709\u66f4\u8907\u96dc\u7684\u6211\u8a8d\u70ba\u4e0d\u5be6\u7528\uff0c\u5927\u5bb6\u53ef\u4ee5\u81ea\u5df1\u53bb\u770b\uff0c\u4e3b\u8981\u662f\u904b\u7528RegisterStartupScript\u548cJavaScript\u7684\u6280\u8853<br \/>\n\u4ee5\u4e0a\u6587\u7ae0\u4ecb\u7d39\u4e86\u4e00\u4e9bASP.NET\u4e2d\u5e38\u7528\u800c\u4e14\u6bd4\u8f03\u5be6\u7528\u7684\u6280\u5de7\uff0c\u5e0c\u671b\u80fd\u5c0d\u5927\u5bb6\u7684\u5be6\u969b\u958b\u767c\u6709\u6240\u88e8\u76ca\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u96a8\u8457\u5fae\u8edf.NET\u7684\u6d41\u884c\uff0cASP.NET\u8d8a\u4f86\u8d8a\u70ba\u5ee3\u5927\u958b\u767c\u4eba\u54e1\u6240\u63a5\u53d7\u3002\u4f5c\u70baASP.NET\u7684\u958b\u767c\u4eba\u54e1\uff0c\u6211\u5011\u4e0d\u50c5\u9700\u8981\u638c &hellip; <a href=\"https:\/\/jason695.why3s.tw\/wordpress\/2007\/04\/09\/%e8%bd%89%e8%b2%bc%e8%a8%ad%e8%a8%88aspnet%e6%87%89%e7%94%a8%e7%a8%8b%e5%ba%8f%e7%9a%84%e4%b8%83%e5%a4%a7%e7%b5%95%e6%8b%9b\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">[\u8f49\u8cbc]\u8a2d\u8a08ASP.NET\u61c9\u7528\u7a0b\u5e8f\u7684\u4e03\u5927\u7d55\u62db<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-274","post","type-post","status-publish","format-standard","hentry","category-net","no-featured-image"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/comments?post=274"}],"version-history":[{"count":0,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"wp:attachment":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}