2013-02-21 74 views
0
RadInputPrompt.Show("Enter the number", MessageBoxButtons.OK, message, InputMode.Text, textBoxStyle, closedHandler: (arg) => 
{ 
    int okButton = arg.ButtonIndex; 
    if (okButton == 0) 
    { 

      //do some check before submit 
      if (string.IsNullOrEmpty(arg.Text)) 
      { 
       MessageBox.Show("Please input the number."); 
       return; //?? 
      } 

      //submit 
    } 
    else 
    { 
     return; 
    } 
}); 

我的問題是: 我做一些數據驗證(例如:只有數字,數字個性化......)之前提交

如果從用戶輸入invaild,我希望提示輸入屏幕仍然可以保留。
如果我使用「返回」關鍵字,它會回到主屏幕。

或者是否有任何其他驗證方式(比如AJAX?),我可以在此提示畫面上使用,而不是在代碼隱藏頁面上進行驗證?

數據驗證

非常感謝!

+0

你能提供一些關於你想要做的事情的更多信息嗎?也許是一個相關的例子或更多的代碼?有數百萬種方法來驗證數據,有些甚至在用戶輸入時也是如此。只需要清理你想要的東西。 – 2013-02-22 13:54:25

+0

我已經做了一些更多的解釋。我希望你能明白我的意思,謝謝! – user1371541 2013-02-22 14:52:29

回答

0

一種技術是在每次用戶單擊確定時保持循環並顯示輸入提示,但未能滿足輸入驗證。如果結果不是有效的數值,您可以看到下面的示例,並且輸入文本框將繼續重複。

向用戶添加某種反饋意味着在提交無效的情況下以前的輸入不可接受也是一個好主意。下面是一個例子,其中輸入文本框的標題在第一次無效提交後改變爲包含指示輸入值必須是有效數字的文本。

注意:Telerik說現在應該使用ShowAsync方法來代替Show方法,因爲它已被棄用。

 string userInput = string.Empty; 
     int okButton = 0; 
     bool firstPass = true; 
     double numericResult; 

     while (okButton.Equals(0) && string.IsNullOrWhiteSpace(userInput)) 
     { 
      string inputBoxTitle = (!firstPass) ? "Enter the number (you must enter a valid number)" : "Enter the number"; 

      InputPromptClosedEventArgs args = await RadInputPrompt.ShowAsync(inputBoxTitle, MessageBoxButtons.OKCancel); 
      okButton = args.ButtonIndex; 
      firstPass = false; 

      if (okButton.Equals(0)) 
      { 
       if (!string.IsNullOrWhiteSpace(args.Text)) 
       { 
        bool isNumeric = double.TryParse(args.Text, out numericResult); 
        if (isNumeric) 
        { 
         // We have good data, so assign it so we can get out of this loop 
         userInput = args.Text; 
        } 
       } 
      } 
     }