Add the radiobuttonlist control to the front-end page.
If (! Ispostback) {per () ;}} protected void btn_toupiao_click (Object sender, eventargs e) {string p_str_ip = request. userhostaddress. tostring (); // obtain the Client IP address httpcookie oldcookie = request. cookies ["userip"]; If (oldcookie = NULL) {int flag = radiobuttonlist1.selectedindex; Switch (FLAG) {Case 0: addcount (server. mappath ("result1.txt"); break; Case 1: addcount (server. mappath ("result2.txt"); break; CA Se 2: addcount (server. mappath ("result3.txt"); break;} clientscript. registerstartupscript (GetType (), "", "alert ('vote successful, thank you! ') ", True); httpcookie newcookie = new httpcookie (" userip "); // defines the new Cookie object newcookie. expires = datetime. maxvalue; // set the cookie validity period // Add a new Cookie variable IPaddress with the value p_str_ip newcookie. values. add ("IPaddress", p_str_ip); response. appendcookie (newcookie); // write the variable to the cookie file} else {string p_str_oldip = oldcookie. values ["IPaddress"]; If (p_str_ip.trim () = p_str_oldip.trim () {clientscript. registerstartupscript (Ge Ttype (), "", "alert ('You have voted. You cannot vote again. Thank you! ') ", True) ;}else {httpcookie newcookie = new httpcookie (" userip "); // defines the new Cookie object newcookie. expires = datetime. maxvalue; // set the cookie validity period // Add a new Cookie variable IPaddress with the value p_str_ip newcookie. values. add ("IPaddress", p_str_ip); response. appendcookie (newcookie); // write the variable to the cookie file int flag = radiobuttonlist1.selectedindex; Switch (FLAG) {Case 0: addcount (server. mappath ("result1.txt"); break; Case 1: addcount (SE Rver. mappath ("result2.txt"); break; Case 2: addcount (server. mappath ("result3.txt"); break;} clientscript. registerstartupscript (GetType (), "", "alert ('vote successful. Thank you for participating! ') ", True) ;}}// display protected string m_str_rate1; protected string m_str_rate3; protected int p_int_count1; protected int p_int_count2 to the front end; protected int p_int_count3; Public void per () {p_int_count1 = readcount (server. mappath ("result1.txt"); p_int_count2 = readcount (server. mappath ("result2.txt"); p_int_count3 = readcount (server. mappath ("result3.txt"); I NT p_int_count = p_int_count1 + p_int_count2 + p_int_count3; If (p_int_count = 0) {lblresult. TEXT = "0 participants in voting";} else {m_str_rate1 = (convert. todouble (p_int_count1) * 100/convert. todouble (p_int_count )). tostring ("0.00") + "%"; m_str_rate2 = (convert. todouble (p_int_count2) * 100/convert. todouble (p_int_count )). tostring ("0.00") + "%"; m_str_rate3 = (convert. todouble (p_int_count3) * 100/conve Rt. todouble (p_int_count )). tostring ("0.00") + "%"; lblbanana. TEXT = m_str_rate1; lblapple. TEXT = m_str_rate2; lblwatermelon. TEXT = m_str_rate3; lblresult. TEXT = "Total" + p_int_count.tostring () + "Participants vote. ";}}// Read the number of votes in the specified path file. Public static int readcount (string p_str_path) {int p_int_count = 0; streamreader SR; Sr = file. opentext (p_str_path); While (Sr. peek ()! =-1) {p_int_count = int. parse (Sr. readline ();} Sr. close (); Return p_int_count;} // Number of votes written to the specified path file public static void addcount (string p_str_path) {int p_int_count = readcount (p_str_path); p_int_count + = 1; streamwriter Sw = new streamwriter (p_str_path, false); Sw. writeline (p_int_count); Sw. close ();}