Follow this example to detect the page refresh in ASP.NET .
- Create sample page name DetectPageRefresh.aspx
The DetectPageRefresh.aspx Page
<asp:Label ID="Label1" runat="server"></asp:Label> <br /> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="Do postback at server side" onclick="Button1_Click" />
The Code Behind
private bool IsPageRefresh = false; public bool IsPageRefresh1 { get { return IsPageRefresh; } set { IsPageRefresh = value; } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ViewState["postids"] = System.Guid.NewGuid().ToString(); Session["postid"] = ViewState["postids"].ToString(); } else { if (ViewState["postids"].ToString() != Session["postid"].ToString()) { IsPageRefresh = true; } else { IsPageRefresh = false; } Session["postid"] = System.Guid.NewGuid().ToString(); ViewState["postids"] = Session["postid"].ToString(); } } protected void Button1_Click(object sender, EventArgs e) { if (!IsPageRefresh1) { Label1.Text = "Page do normal postback"; } else { Label1.Text = "Page refresh"; } }
The output
- Click on the button.
- and then press F5 button to refresh page
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
0 comments:
Post a Comment