顯示具有 ASP.NET 標籤的文章。 顯示所有文章
顯示具有 ASP.NET 標籤的文章。 顯示所有文章

2018/08/10

[Visual Studio] 解決程式碼在文字編輯器上無法區塊折疊的問題

問題


在開發機的 Visual Studio 2017 發現在編輯程式碼時無法區塊折疊

預期


如下圖左方一般 (同樣都是 .aspx 的檔案, 其中一台就沒有可折疊的可點)



解決方法


編輯 -> 大綱 -> 啟用自動大綱



不過目前發現這樣啟用只限單頁,若是其他頁要開啟,就要重複步驟。如果有任何先進發現自動設定啟用的方式,歡迎告知!

至少目前在編寫 aspx 的 HTML 時可以把不動的區塊折疊起來了!

2018/05/30

[ASP.NET] Web Forms 踩雷記 - App_Code

在很久很久年後的今天,又重新開始寫 Web Forms 的專案。

如果在不指定技術的情況下,採 Windows Server 主機的客戶,我通常都以 ASP.NET MVC 為主要技術。但這回客戶指定採用 Web Forms 只因內部技術人員只會這個。

好吧!只好硬著頭皮再來重拾技能~

狀況


開了個 Web Forms 的應用程式,開始撰寫程式,由於太長時間用 MVC,結構設計上要來調整一下,為適應 Web Forms 以免開了一堆資料夾,想說程式就寫在 App_Code 好了!爆雷!

Class 找不到!找不到!找不到!

解決方案


現今是開 Web 應用程式專案,而非 Web Site 專案,在 App_Code 裡的程式是不會被編譯進來的!

把程式搬到其他資料夾 (例: Services/ ) 重編譯過就搞定

僅僅是重拾技能小記,新手專用 XD

2010/05/06

[ASP.NET] 轉換 ArrayList 至字串陣列

VB:

Dim str() As String = arrList.ToArray(GetType(String))

C#:

string[] strings = (string[])arrList.ToArray(typeof(string));

2010/04/27

[ASP.NET] Forms 登入驗證

命名空間
System.Web.Security

驗證
FormsAuthentication.RedirectFromLoginPage(username, true)

登出
FormsAuthentication.SignOut()

查證是否驗證
User.Identity.IsAuthenticated

ASP.NET MVC (在 Controller 的 Action 前加 Authorize 屬性)
[Authorize]
e.g.
[Authorize]
public ActionResult Index() { return View(); }



相關資料:

[ASP.NET] 類別中讀取 Session

匯入命名空間
Imports System.Web.HttpContext

在類別中使用Session
Current.Session("sessionName")

2009/07/10

MS Chart Control 設置

在 ASP.NET 中 MS Chart Control 的設置方法

1. 修改 web.config 檔

在 system.web 的 httpHandlers 區塊加入以下設置:

< path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false">


在 system.webserver 的 handlers 區塊加入以下設置:

< name="ChartImageHandler" precondition="integratedMode" verb="GET,HEAD" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">



2. 暫存目錄路徑設定
在 web.config 中 appSettings 的區塊中加入圖片暫存資料夾的設定
或是直接建立 c:\TempImageFiles\ 的資料夾 (預設暫存夾目錄)

p.s. 若無建立此暫存資料夾,會出現錯誤訊息:
圖表處理常式組態中有無效的暫存目錄 [c:\TempImageFiles\]。

圖表儲存方法 (storage=file|memory|session) 及目錄指定 (dir|url), 有以下方法:

絕對路徑:

< key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;">
< key="ChartImageHandler" value="storage=memory;timeout=20;dir=c:\TempImageFiles\;">
< key="ChartImageHandler" value="storage=session;timeout=20;dir=c:\TempImageFiles\;">


相對路徑:

< key="ChartImageHandler" value="storage=file;timeout=20;url=~/TempImageFiles/;">


3. 複製 System.Web.DataVisualization.dll 至 bin/ 資料夾
安裝的 Chart Control 預設放置路徑:
C:\Program Files\Microsoft Chart Controls\Assemblies
將 System.Web.DataVisualization.dll 複置至 Web 專案的 bin/ 中即可

************ 以上為基本設定 ************

頁面端需加入
< %@ Register Assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>


在程式端則需引入
System.Web.UI.DataVisualization.Charting


參考資源:

2009/05/21

下拉式選單控制項在 ListView 的 InsertItemTemplate 資料繫結問題

下拉式選單控制項在 ListView 中,除了在 InsertItemTemplate 之外的資料繫結都沒問題

若是用 SelectedValue='<%# Bind("DepartmnetId") %>' 的繫結方式,就會產生錯誤訊息

錯誤訊息:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control
這項已被列為 ASP.NET 的 bug,將於下個發佈版本將會被修復
但在修復之前,可在 ItemInserting 的事件中來指定選擇值,例如:

e.Values("DepartmentId") = CInt(CType(e.Item.FindControl("ddlDepartment"), DropDownList).SelectedValue)

延伸閱讀:
DataBinding on DropDownList's SelectedValue property not working in the InsertItemTemplate of a ListView
ASP.NET 3.5 ListView with DropDownList in InsertItemTemplate