Paul Rajs

Paul Rajs

  • NA
  • 641
  • 147.2k

in this code how can i get the Text of Button in C#

Jan 31 2018 4:14 AM
hi developers i am using this code it is working fine for me , but i am having a small doubt .
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3. string query = string.Format("SELECT roomno from AD_Rooms_Master order by roomno");  
  4. try  
  5. {  
  6. DataTable dt = GetData(query);  
  7. for (int i = 0; i < dt.Rows.Count; i++)  
  8. {  
  9. Button btn = new Button();  
  10. btn.ID = "btn" + (i + 1);  
  11. btn.Text = dt.Rows[i]["roomno"].ToString();  
  12. btn.Click += btnLoadButton_Click;  
  13. pnl_btns.Controls.Add(btn);  
  14. }  
  15. }  
  16. catch (Exception ex)  
  17. {  
  18. ScriptManager.RegisterStartupScript(thisthis.GetType(), "Message""alert('Error occured : " + ex.Message.ToString() + "');"true);  
  19. }  
  20. finally  
  21. {  
  22. //cmd = null;  
  23. //conn.Close();  
  24. }  
  25. }  
  26.   
  27. protected void btnLoadButton_Click(object sender, EventArgs e)  
  28. {  
  29. ClientScript.RegisterClientScriptBlock(this.GetType(), "button""<script type = 'text/javascript'>alert('Room no " + (sender as Button).Text + " selected');</script>");  
  30. }  
could you tell me instead of this how can i get the value by using c# code , because then only i am validate the answer is correct or wrong .
 
ClientScript.RegisterClientScriptBlock(this.GetType(), "button", "<script type = 'text/javascript'>alert('Room no " + (sender as Button).Text + " selected');</script>");
 
thanks with
 
Paul.S
'Man becomes what he thinks about'

Answers (1)