c# - How do I fix the error message: Event validation is enabled; arguments originate from the server control that originally rendered them -


i have problem 2 checkboxes!

private checkbox rdyes; private checkbox rdno;              rdyes = new checkbox();             rdyes.text = "yes";             rdyes.checked = false;             rdno = new checkbox();             rdno.text = "no";             rdno.checked = false; 

error:

invalid postback or callback argument. event validation enabled using in configuration or <%@ page enableeventvalidation="true" %> in page. security purposes, feature verifies arguments postback or callback events originate server control rendered them. if data valid , expected, use clientscriptmanager.registerforeventvalidation method in order register postback or callback data validation

i instantiating checkboxes in :

    protected override void createchildcontrols()     {             this.controls.add(rdyes);             this.controls.add(rdno);      } 

and need check 1 checkbox.

enter image description here

and need check 1 checkbox...

if need check 1 checkbox can better try use radio button.

however if want make sure 1 checkbox selected try this:

checkbox prevchecked; private void clickcheckbox(object sender, eventargs e)  {    checkbox mycheckbox = sender checkbox;    if(mycheckbox != prevchecked && prevchecked!=null) prevchecked.checked = false;    {        prevchecked = mycheckbox.checked ? mycheckbox : null;    } } 

and if want page should not refreshed can try set autopostback="false" checkbox property.

rdyes = new checkbox(); rdyes.text = "yes"; rdyes.checked = false; rdyes.autopostback=false; rdno = new checkbox(); rdno.text = "no"; rdno.checked = false; rdno.autopostback=false;  

Comments