Dynamically created requiredfieldvalidator bypasses client side validation

时光总嘲笑我的痴心妄想 提交于 2019-12-02 07:44:39

You can to check your code with jquery.

function TextBoxValidate() {
$('input:[type="text"]:[id*="TextBox1"]').each(function () { var txtId = this.id; $('span').each(function () { if (this.controltovalidate == txtId) ValidatorValidate(this); }); }); 
}
function InitValidationOnClick()
{  
$('input:[id*="Button1"]').each(function(){$(this).on('click', function(){TextBoxValidate(); return Page_IsValid;});});
// or other case
//$('form:[id*="form1"]').each(function(){$(this).on('submit', function(){TextBoxValidate(); return Page_IsValid;});});
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InitValidationOnClick);

If validator exists in page it will validate on click (submit) event client-side.

AJAY KRISHNA VEMU

Hello All Try This one For Radio Buttons Along With RequiredField Validator

Code

    TableRow trow4 = new TableRow();
    trow4.Style.Add("width", "100px");
    TableCell tcel4 = new TableCell();
    Label lb4 = new Label();
    lb4.Text = Resources.QcLabelName.Gender;
    tcel4.Controls.Add(lb4);
    CSSCell(tcel4);
    table.Rows.Add(trow4);
    RadioButtonList rblist = new RadioButtonList();
    rblist.ID = "rbtnmalendfemale";
    rblist.Items.Add("Male");
    rblist.Items.Add("Female");
    tcel4.Controls.Add(rblist);
    trow4.Cells.Add(tcel4);
    table.Rows.Add(trow4);
    rblist.Visible = true;
    RequiredFieldValidator rFV5 = new RequiredFieldValidator();
    TableCell tcl46 = new TableCell();
    rFV5.ControlToValidate = "rbtnmalendfemale";
    rFV5.ErrorMessage = "Gendor Selection Is Mandatory";
    rFV5.Style.Add("color", "Red");
    rFV5.ID = "Reqfield9";
    tcl46.Controls.Add(rFV5);
    trow4.Cells.Add(tcl46);
    table.Rows.Add(trow4);
    rFV5.Visible = true;******
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!