In this example I’ve put a Label and a Button on the page, on click the label Text becomes Hello and when I refresh the page label's text again becomes Hello
<%@ Page Language="C#" AutoEventWireup="true"CodeFile="Default.aspx.cs" Inherits="_Default" %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form2" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Label">asp:Label><br /> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />div> </form> </body> </html> |
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString()); } } protected void imgbtn_Click(object sender, ImageClickEventArgs e) { //Label2.Text = imgbtn.ToolTip; } protected void Button1_Click(object sender, EventArgs e) { if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString()) { Label1.Text = "Hello"; Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString()); } else { Label1.Text = "Page Refreshed"; } } protected void Page_PreRender(object sender, EventArgs e) { ViewState["CheckRefresh"] = Session["CheckRefresh"]; } } |
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
|
Subscribe by RSS
Subscribe by Email
4 comments :
Super...Great Work!!!
i want redirect when page get refreshing what should i do...but i also try responce.redirect mehod but it wont work..plz help me..
i got this error for session object...plz help
Object reference not set to an instance of an object.
thanks in adv