2009-03-20 12 views

答えて

0

RequiredFieldValidatorはジョブを実行する必要がありますか? あなたがバリデータについての詳細を知りたいならば、あなたはCustomValidatorを使用する必要がありますここでhttp://www.codeproject.com/KB/validation/aspnetvalidation.aspx

+0

RFVを使用することはできませんが、両方のテキストボックスが空の場合のみ、エラーメッセージ – peter

+0

を表示します。CustomValidatorを使用することはできますが、1回しか使用していないので、 .. – Peter

0
protected submit_click() 
{ 
if((TextBox1.Text=="")||(TextBox2.Text=="")) 
    { 
    print that error message 
    } 
} 
+0

ありがとうsevugarajan、私はJavaスクリプトを使用してカスタムバリデーターが必要だと思っていましたが、それは動作するかどうかを私に見せてくれます – peter

0
if (TextBox1.Text == String.Empty && TextBox2.Text == String.Empty) 
{ 
Label1.Text = "Your error message here"; 
} 
else 
{ 
//continue your logic here 
} 
+0

あなたの答えは – peter

0

CustomValidatorは、コールバックメソッドを提供します。あなたは、他のバリデータのようにそれを使用して、[コントロール名] _ServerValidateメソッドで次のコードを書くことができますスケーラブルな関数に

args.IsValid = TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0; 
+0

ありがとうございました。あなたの貴重なコメントのためにcustomvalidator – peter

0

要約:

private bool Validate(params TextBox[] boxes) { 
    foreach (var box in boxes) 
     if (string.IsNullOrEmpty(box.Text)) 
      return false; 
    return true;    
} 

その後、

if(Validate(TextBox1, TextBox2, ...)) { 
    /// Do the good stuff 
} else { 
    /// throw error 
} 
で呼び出します
+0

ありがとう – peter

関連する問題