Faisal

Faisal

  • 1.6k
  • 73
  • 1.5k

On="1" and Off="2" within one click

Aug 6 2019 11:47 PM
I'm using one button for "on and "off" in asp.net c#. When i click that button it is "on" and when i click that same button second time it is "off". Now i want to do this within one click. This means that once i click and hold that button it should be "on" till i release the button, when released it should be "off". Please let me know how can i do that !
 
  1. protected void Page_Load(object sender, EventArgs e)  
  2.     {  
  3.         ardo = new SerialPort();  
  4.         ardo.PortName = "COM5";  
  5.         ardo.BaudRate = 9600;  
  6.     }  
  7.     protected void BlueOn(object sender, EventArgs e)  
  8.     {  
  9.         if(Session["currentState"] == null)  
  10.            Session["currentState"] = "2";  
  11.   
  12.        if(Session["currentState"].ToString() == "1")  
  13.          {  
  14.   
  15.             Session["currentState"]= "2";  
  16.          }  
  17.          else  
  18.          {  
  19.   
  20.             Session["currentState"]= "1";   
  21.          }  
  22.         ardo.Open();  
  23.         ardo.Write(Session["currentState"].ToString());  
  24.         ardo.Close();  
  25.   
  26.     } 
 

Answers (3)