Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Zia Mughal
  Where is Zia Mughal?
 Rawalpindi
 Pakistan
 Zia Mughal
 To: Santosh Mishra
  Where is Santosh Mishra?
 Lucknow
 India
 Santosh Mishra
 Tags
Subject: RE: .Net Variable problem
Thread ID: 416185 Message ID: 416189 # Views: 48 # Ratings: 2
Version: Unknown Category: C#.NET
Date: Tuesday, December 23, 2014 8:51:12 AM         
   


> At my learning stage I have a prob.
>
> I declared a variable "branch" in Page_Load event
> but when I tried to use it in Button2_Click event, it is giving error.
>
> Please help.....
>
> It would good for me, if help will be in my level
>
>
>
> protected void Page_Load(object sender, EventArgs e)
> {
> string branch= null;
> if (Session["sfld1"].ToString() == "ITOFF")
> {
> branch = "IT";
> Label1.Text = "INDIRA NAGAR BRANCH";
> }
> }
>
> protected void Button2_Click(object sender, EventArgs e)
> {
> SqlConnection con = new SqlConnection("Server=SDCHO\\SQLEXPRESS;Database=LoginPage;Trusted_Connection=true");
> con.Open();
> SqlCommand cmd = new SqlCommand();
>
> cmd.CommandText = "Update LeaveDataTable SET BRANCH_OFF= @branch_off1 where Lsr=@Lsr1 and Lbr=@Lbr1";
>
> cmd.Parameters.AddWithValue("@branch_off1", RadioButtonList2.SelectedItem.Value.ToString());
> cmd.Parameters.AddWithValue("@Lsr1", Convert.ToInt32(TextBox1.Text));
>
> cmd.Parameters.AddWithValue("@Lbr1", branch);
>
> cmd.Connection = con;
> int result = cmd.ExecuteNonQuery();
>
>
> GridView1.DataBind();
> con.Close();
> }


Define your variable as public.
e.g


namespace Your.Namespace
{
public class Global : System.Web.HttpApplication
{
private static int someVariable = 0;
public static int SomeVariable
{
get
{
return someVariable;
}
set
{
someVariable = value;
}
}
// Rest of Global class here
}

You can then use or change it like this in a page:
Your.Namespace.Global.SomeVariable = SomeValue;


Regards

Zia Mughal
Pcland Software inc. Pakistan
http://www.pcland.com.pk
http://pclandpk.blogspot.com

ENTIRE THREAD

.Net Variable problem Posted by Santosh Mishra @ 12/23/2014 8:22:55 AM
RE: .Net Variable problem Posted by Borislav Borissov @ 12/23/2014 8:36:49 AM
RE: .Net Variable problem Posted by Zia Mughal @ 12/23/2014 8:51:12 AM
RE: .Net Variable problem Posted by Anil Sharma @ 12/25/2014 7:25:28 PM