i have a web page.i want to define a varible that can use in all events in this form.
i write it such as below
partial class : System.Web.UI.Page
{
{
if (!page.ispostback) tb.name="ajjj";
}
{
protected void btnSave_Click(object sender, EventArgs e){
response.write(tb.name);
}
}
once at first tb.name get value and when i click on btnsave this value is null.
How can i maintain value in this varible?
protected void Page_Load(object sender, EventArgs e)
Amit ChoudharyPosted Feb 22, 2011, 4:16 AM
since the HTTP protocol is stateless so when refresh or postback the page everything on the page get re-evaluated and lost its previous values so use session variable to persist the value of your variables.
Tbl_list tbl=new Tbl_list();
Session["tbl"]=tbl;
remember in you event every time you update the value of tbl variable you need to update the session variable also i.e. Session["tbl"].
Hope this helps you.
Thanks.
Jaganathan BantheswaranPosted Feb 22, 2011, 4:04 AM
Try this logic !
partial class : System.Web.UI.Page
{
Tbl_List tb;if (!page.ispostback)
{
tb.name="ajjj";
tb = new Tbl_sList();
}
}Else use the Session or ViewState Variables like
in Page load
Session["Name"] = "Jagan";
Where ever you need the Name then use the below
If you feel this helped you please Make this as ANSWER