Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public partial class Login : System.Web.UI.Page
{
 
    protected void Page_Load(object sender, EventArgs e)
    {
   
    }
    public void Button1_Click(object sender, EventArgs e)
    {
 
        String Strt_Address = TextBox1.Text;
        String End_Address = TextBox2.Text;
 
        string geocodeUrl1 = string.Format(@"http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Strt_Address);
 
        string geocodeUrl2 = string.Format(@"http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", End_Address);
 
        
 
        XmlDocument geocodeXmlDoc1 = new XmlDocument();
        geocodeXmlDoc1.Load(geocodeUrl1);
 
        XmlDocument geocodeXmlDoc2 = new XmlDocument();
        geocodeXmlDoc2.Load(geocodeUrl2);
 

        XmlNamespaceManager XmlMngr1 = new XmlNamespaceManager(geocodeXmlDoc1.NameTable);
        XmlMngr1.AddNamespace("geo", @"http://www.w3.org/2003/01/geo/wgs84_pos#");
 
        XmlNamespaceManager XmlMngr2 = new XmlNamespaceManager(geocodeXmlDoc2.NameTable);
        XmlMngr2.AddNamespace("geo", @"http://www.w3.org/2003/01/geo/wgs84_pos#");
 

        String sLong1 = geocodeXmlDoc1.DocumentElement.SelectSingleNode(@"//geometry/location/lat", XmlMngr1).InnerText;
        String sLat1 = geocodeXmlDoc1.DocumentElement.SelectSingleNode(@"//geometry/location/lng", XmlMngr1).InnerText;
 
        String sLong2 = geocodeXmlDoc2.DocumentElement.SelectSingleNode(@"//geometry/location/lat", XmlMngr2).InnerText;
        String sLat2 = geocodeXmlDoc2.DocumentElement.SelectSingleNode(@"//geometry/location/lng", XmlMngr2).InnerText;
 
        Label1.Text = sLong1 + ", " + sLat1;
        Label2.Text = sLong2 + ", " + sLat2;
 

        Page.ClientScript.RegisterStartupScript(Page.GetType(), "script",
        "calcRoute()", true);
        }
 
      }


so i want to access this String sLong1, sLat1, sLong2, sLat2 in another class

let say i have harversine class

C#
public class harversine {

        // i want to access those varables in here!!!!
           how can i do that
        
     }


Added the OP's comment from solution.

Check my value passing metod is correct or not


C#
public partial class Login : System.Web.UI.Page
{
    //public String End_Address = string.Empty;
    public static Double elong1, elat1;
 
   public static Double Elong1
    {
        get { return Login.elong1; }
        set { Login.elong1 = value; }
    }
 
       public static Double Elat1
    {
        get { return Login.elat1; }
        set { Login.elat1 = value; }
    }
 
 public void Button1_Click(object sender, EventArgs e)
    {
 
String sLong1 = geocodeXmlDoc1.DocumentElement.SelectSingleNode(@"//geometry/location/lat", XmlMngr1).InnerText;
        String sLat1 = geocodeXmlDoc1.DocumentElement.SelectSingleNode(@"//geometry/location/lng", XmlMngr1).InnerText;
 

 
elong1 = Convert.ToDouble(sLong1);
elat1 = Convert.ToDouble(sLat1);
 
}


// this is a sample class
C#
public class harversine
    {
 
     String loudlong1 = Convert.ToString(elong1);
     String loudlat1 = Convert.ToString(elat1);
 
       // let say i want pass Fanswer to Textbox in button click event 
     String Fanswer = loudlong1 + ", " + loudlat1;
 
}



this all are samples and i want to see if this correct or not before i'm writing a original code.

i'm a student and i'm new to the field as well. so someone please kindly help me to correct this if i'm wrong.
Posted
Updated 30-Jun-13 23:15pm
v4
Comments
_Amy 1-Jul-13 3:17am    
This is third time you posted your question. Delete your both questions. Otherwise it'll be considered as spam/abusive here.
someone check this and tell me way to access value in class?[^]
i want to access variables in another class which i assigned in login class?... can someone tell me my methods are okay or not..[^]

1 solution

first make the varibale global and public
and then access that variable by class object name
like
C#
Login l=new Login
string str=l.loudlong1 
 
Share this answer
 
v2
Comments
promod madushan 1-Jul-13 3:43am    
this method is correct know?
vinayakJJ 1-Jul-13 5:45am    
yes it is correct

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900