Tech
Forums
Jobs
Books
Events
Live
Interviews Prep
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
Session variable and Application variable
Mohit Kapoor
Jul 15 2016 4:37 PM
325
Reply
Why value of Session variable and Application variable updates on page reload !!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace part_5_WebApplication2
{
public partial class Session1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["Click"] == null)
{
Session["Click"] = 0;
}
TextBox1.Text = Session["Click"].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int click_count = (int)Session["Click"] + 1;
TextBox1.Text = click_count.ToString();
Session["Click"] = click_count;
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
------------------------------------------------------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Session1.aspx.cs" Inherits="part_5_WebApplication2.Session1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click me !" />
</div>
</form>
</body>
</html>
Attachment:
upload.zip
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
import data to xls file and show data grid & store data mvc4
how to remove data that bind inside repeater in c#