Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. private Boolean IsPageRefresh = false;
  2. protected void Page_Load(object sender, EventArgs e)
  3. {
  4. if (!IsPostBack)
  5. {
  6. ViewState["postids"] = System.Guid.NewGuid().ToString();
  7. Session["postid"] = ViewState["postids"].ToString();
  8.  
  9. }
  10. else
  11. {
  12. if (ViewState["postids"].ToString() != Session["postid"].ToString())
  13. {
  14. IsPageRefresh = true;
  15. Button1.Enabled = false;
  16. Button1.Text = "נשלח בהצלחה";
  17. }
  18. Session["postid"] = System.Guid.NewGuid().ToString();
  19. ViewState["postids"] = Session["postid"];
  20. }
  21. }
  22.  
  23. protected void Button1_Click(object sender, EventArgs e)
  24. {
  25.  
  26. if (!IsPageRefresh)
  27. {
  28. submitCrap();
  29. }
  30. else // If Page Refreshed
  31. {
  32. // Do nothing
  33. }
  34. }
  35.  
  36. void submitCrap()
  37. {
  38. try
  39. {
  40.  
  41. using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"D:\IDs.txt", true)) //(Server.MapPath("~/data.txt")
  42. {
  43. writer.WriteLine(idNum.Text);
  44. //writer.WriteLine(HttpContext.Current.Request.UserHostAddress);
  45. }
  46. Button1.Text = "נשלח בהצלחה";
  47. Button1.Enabled = false;
  48. //Response.Redirect("thanks.htm");
  49. //Server.Transfer("default.aspx",false);
  50. }
  51. catch
  52. {
  53. // There was an error in writing to the file but I couldn't care less.
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement