Guest User

Untitled

a guest
Jan 15th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. <asp:TemplateField>
  2. <ItemTemplate>
  3. <asp:HyperLink ID="HyperLink1" runat="server"
  4. NavigateUrl='<%# Eval("Post_ID", "~/RCA.aspx?Post_ID={0}") %>'
  5. Text="SEND"></asp:HyperLink>
  6. </ItemTemplate>
  7.  
  8. <asp:Button ID="btnRCA" runat="server" onclick="Button1_Click"
  9. Text="Assign RCA" Width="147px" />
  10.  
  11. //When linked to RCA.aspx from Home.aspx, a parameter called ShowButton=1 is included
  12. //in the URL.
  13.  
  14. <asp:HyperLink ID="HyperLink1" runat="server"
  15. NavigateUrl='<%# Eval("Post_ID", "~/RCA.aspx?Post_ID={0}&ShowButton=1") %>'
  16. Text="SEND"></asp:HyperLink>
  17.  
  18. //By default, since you want the button to NOT appear for all incoming traffic EXCEPT
  19. //that which came from Home.aspx, the button's Visible property is set to false.
  20.  
  21. <asp:Button ID="btnRCA" runat="server" onclick="Button1_Click"
  22. Text="Assign RCA" Width="147px" Visible="false" />
  23.  
  24. protected void Page_Load(object sender, EventArgs e)
  25. {
  26. //If the querystring has a parameter called ShowButton and it's equal to "1",
  27. //then set the button to Visible = true.
  28. //Else, do nothing, keeping the button in it's default, Visible=false state.
  29.  
  30. //By putting this in an "IsPostback == false" check, you can guarantee that this will
  31. //only happen on first page_load, and won't be triggered again even if you do other
  32. //actions in the page that cause Postback
  33.  
  34. //For example, if you don't use this !IsPostback check, and you end up creating some
  35. //new function that causes the button to be hidden again, but then you make a
  36. //selection from a dropdown list that causes postback, you will trigger the call to
  37. //make the button Visible again, even though that's probably what you don't want at
  38. //this point, since your other new function set it to Visible = false.
  39.  
  40. if (!IsPostback)
  41. {
  42. if (Request.QueryString["ShowButton"] == "1")
  43. {
  44. RCAbtn.Visible = true;
  45. }
  46.  
  47. if (Request.QueryString["Post_ID"] != null)
  48. {
  49. //do whatever you need to with the post ID
  50. }
  51. }
  52. }
  53.  
  54. Response.Redirect("RCA.aspx?Post_ID=1234"); //button will be invisible
  55.  
  56. Response.Redirect("RCA.aspx?Post_ID=1234&ShowButton=1"); //button will be visible
  57.  
  58. string currenturl = Request.Url.ToString(); //get the current URL
  59. string urlToSend = currenturl.Substring(0, currenturl.IndexOf("?")); //cut off the QueryString entirely
  60. urlToSend += "?Post_ID=" + Request.QueryString["Post_ID"]; //re-append the Post_ID
  61.  
  62. protected void Page_Load(object sender, EventArgs e)
  63. {
  64. if (Request.QueryString["Post_ID"] != null)
  65. {
  66. btnRca.Visible = true;
  67. }
  68. }
Add Comment
Please, Sign In to add comment