Hi Mehram,
You need to check the Session value whether its zero or not.
Based on the condition, set the TextBox and Button Enabled property to true or false.
Refer below sample.
HTML
<asp:TextBox ID="txtName" runat="server" />
<asp:Button ID="btnSave" Text="Save" runat="server" />
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
Session["IsActiveYear"] = "0";
EnableDisableControls();
}
}
private void EnableDisableControls()
{
txtName.Enabled = Session["IsActiveYear"].ToString() != "0";
btnSave.Enabled = Session["IsActiveYear"].ToString() != "0";
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Session("IsActiveYear") = "0"
EnableDisableControls()
End If
End Sub
Private Sub EnableDisableControls()
txtName.Enabled = Session("IsActiveYear").ToString() <> "0"
btnSave.Enabled = Session("IsActiveYear").ToString() <> "0"
End Sub
Screenshot