2011-10-28 51 views
5

我正在創建一個網站應用程序(ASP.NET,C#),我只想知道顯示錯誤/警告消息的最佳方式。通過MessageBox或通過一個標籤執行它會更好嗎?只需要一些建議。在網站應用程序上顯示錯誤/警告消息的最佳方式是什麼?

+4

什麼樣的信息?驗證?頁面未找到錯誤?更具體地說 –

+2

不太值得2票反對的IMO,這是一個完全有效的問題。 – Mantorok

+2

@ Googler - 僅供參考,許多人都已經低估了,但這個問題是合理的。請更具體地說明你的問題。並將其標記爲答案,如果你得到你正在尋找的東西。 :) – Win

回答

-1

有很多網站使用谷歌,給這個話題的好概述。 here就是一個很好的例子。

+0

czuroski:異常處理如何成爲這個問題的一個很好的例子? –

+0

我可能誤解了這個問題。我認爲這個問題正在尋找一種方法來處理異常,並在必要時將它們顯示給用戶。 – czuroski

1

首先,你應該驗證一切服務器端,因爲所有的客戶端機制,可以規避。

顯示錯誤消息的常規約定是將消息與包含無效信息的字段配對。

您還可以使用HTML5屬性或JavaScript添加客戶端驗證,或者您可以將兩者結合使用,但警告仍應與字段配對(並且不管您是否喜歡樣式)。

<label>First name<br> 
<input type="text" name="firstname" required></label> 
<span class="error">You must enter a first name</span> 
1

老實說,這取決於你希望你的應用程序工作的方式。如果您想要實時驗證用戶輸入(例如訂閱表單),那麼在離開文本框時絕對不需要JavaScript警報。所以在那種情況下,我更喜歡Sohnee描述的內聯方式。

但是,如果您想要顯示應用程序關鍵操作的失敗消息,我會使用JavaScript警報,或者如果回發事件引發警告(在代碼後面),您可以將它們寫入容器中一個div或左右),這將在頁面呈現時可見。

1

對於服務器端驗證,您可以編寫一個自定義控件(我這樣做)來在整個站點中持續顯示消息。

enter image description here

對於客戶端驗證,您可以使用驗證摘要。

<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" 
    ShowMessageBox="true" ShowSummary="false" /> 
1

人,

我喜歡Bootstrap from twitter,這是更快,更容易的Web開發時尚,直觀,強大的前端框架。

[]的

1

請明確你想要驗證什麼。如果您正在驗證包含用戶名/密碼的登錄頁面,則顯示「無效的用戶名/密碼」的標籤就足以讓用戶輕鬆識別。爲用戶可以輕鬆通知的標籤提供顏色。

1

我寧願做這樣: -

this.RegisterClientScriptBlock(typeof(string), "key", string.Format("alert('{0}');", ex.Message), true); 
1
There are many ways you can display the error message. 

1)Simple Message Box.You may need add System.Windows as namespace in application. 

2)The same message box look and feel you can create using the below code, 

this.RegisterClientScriptBlock(typeof(string), "key", string.Format("alert('{0}');", ex.Message), true); 

3)Using InBuilt Asp.net validation control like Required Field Validator,RangeValidator,Validatio Summary. 

4)Place a Label control on each page,use it as when required to display error msg. 

5)Define a validation class,create rules and error message commonly used across apllications. 

6)Using Javascript prompt and alert also,you can display it. 
相關問題