Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
//global object for radiobutton1 is created for access all over to form
		static RadioButton RadioButton1 = new RadioButton();       
		
		
		//here i am assinging in particular div which id is "RadioDiv1" 
		
						Control myControl1 = FindControl("RadioDiv1");
						myControl1.Controls.Add(RadioButton1);
                        RadioButton1.Enabled = true;
                        RadioButton1.EnableViewState = true;
                        RadioButton1.AutoPostBack = false;
                        RadioButton1.ID = "RadioButton1";
                        myControl1.Controls.Add(new LiteralControl(""));                     
                        RadioButton1.CheckedChanged += new EventHandler(RadioButton1_CheckedChanged);
						
						
		//this is the checkedChanged event 				
		private void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (!RadioButton1.Checked)
            {
                RadioButton1.Checked = true;

            }
            else 
            {
                RadioButton1.Checked = false;
            }
        }
		
		//But after clicking on the radiobutton1 the checked changed event is not fired, I am checking the value of Radiobutton1.checked == true 
		// even after select it gives me false .
		
				string user_ans = "";
                if (RadioButton1.Checked == true)
                {
                    user_ans += "A";
                }


Note:- here radiobutton is object is created at the page load time but iam assign its property dynamically , and at the starting i am not assigning its checked value .I am not able to understand what's happening please help me to resolve this
Posted
Updated 4-Aug-15 2:06am
v2
Comments
Ralf Meier 4-Aug-15 6:08am    
OK ... at first :
what is the sense of the Negation of the CheckState in the Eventhandler-Script ?
To which scripts belong all the other code-parts exect the Event-Handler ?
nits23 4-Aug-15 7:29am    
@Ralf Meier Sir i am a new bie to Coding , what are you asking am not able to get you ?
can you explore more by which i am able to clarifying my doubt.
Ralf Meier 4-Aug-15 8:39am    
If the 2 Solutions from gunjalgajjar are not useful for you :
please explain you issue and your plan once more with more Details.
What from my 2 questions was not clear for you ?
nits23 4-Aug-15 9:29am    
@Ralf Meier sir actually am creating online exam scenerio and Here radiobutton features is for multiple options for a single Question , user had to click it for right answer , here i am dynamically creating the radiobutton because i want to randomize the multiple options . on the text basis from the db i am not doing randomization because my db architecture design is too complicated , and in my form i am having two button 1. Next 2. skip. By clicking on next button I also tried to find right and wrong answer in this i am having problem when user click on a specific options at that time neither that Radiobutton_checkchanged event raised nor RadioButton1.checked value is becoming true . by that i am not able to calculate the number of answers given correct by user. so how to do that sir , help me ?
thanks in advance.!!
Ralf Meier 4-Aug-15 14:23pm    
I would help you - but in the moment I don't know how ...
I don't understand exactly what you doing and how you do it.
Perhaps you give some more examples, description and I think a Screenshot would be useful too.

you can try a function in autopostback=true


if(!ispostbck)
{
RadioButton1_CheckedChanged(this,null);
}


it may help you..

 
Share this answer
 
Comments
nits23 5-Aug-15 2:24am    
@senthil_Kumar its not working bcoz if you made autopostback = true and then we are going to check i.e. if(!IsPostBack) -> it ll always return false so after that we are not going to if(true) body by that our checkedChanged event is not going to work . Thanks For Your answer.
"RadioButton1.AutoPostBack = false;"

if you want to call server side checkedchange event you need to set AutoPostBack flag to true
 
Share this answer
 
Comments
nits23 4-Aug-15 7:26am    
@gunjalgajjar its not working even after i am making autopostback to true its not working . It is giving me the value false.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900