2011-04-07 67 views
0

我正在使用SandBox解決方案(SharePoint 2010)。以下是我的代碼驗證控件無法在SandBox解決方案下工作

[ToolboxItemAttribute(false)] 
public class TestValidationControl : WebPart 
{ 
    protected override void CreateChildControls() 
    { 
     Label lblApplicationTitle = new Label(); 
     lblApplicationTitle.Text = "Application Title"; 
     this.Controls.Add(lblApplicationTitle); 

     RequiredFieldValidator rfvApplicationTitle = new RequiredFieldValidator(); 
     rfvApplicationTitle.ControlToValidate = "txtApplicationTitle"; 
     rfvApplicationTitle.ErrorMessage = "*"; 
     rfvApplicationTitle.EnableClientScript = true; 
     this.Controls.Add(rfvApplicationTitle); 

     TextBox txtApplicationTitle = new TextBox(); 
     txtApplicationTitle.ID = "txtApplicationTitle"; 
     this.Controls.Add(txtApplicationTitle); 

     Button btnSave = new Button(); 
     btnSave.Text = "Save"; 
     btnSave.CausesValidation = true; 
     this.Controls.Add(btnSave); 
    } 
} 

當我點擊保存按鈕頁面後回傳。如果我不在文本框中輸入,頁面不應該回發。

+0

您是否嘗試先創建文本框,然後再使用requiredfieldvalidator? – 2011-04-10 09:40:28

+0

讓我嘗試一下。 – 2011-04-13 04:29:20

回答

0

可能會使用ValidationGroup屬性使其正常工作

+0

它正在工作,但問題是,當我點擊按鈕它回發。但讓我試一試你的建議。 – 2011-04-13 04:28:43

相關問題