Q:

Trying to take user input and write to a file

i'm having a problem where I am trying to save the geolocation of an address unto a file.  I am using hidden labels to transfer the information.
on the client side button event I have: 
   function save() {
        document.getElementById("hidLat").value = y;
        document.getElementById("hidLon").value = x;
        <% saveAddress s = save(); %>
   }

and in c# I have:
   protected saveAddress save()
   {
        saveAddress s = new saveAddress();
        s.latitude = hidLat.Value;
        s.longitude = hidLon.Value;

        using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\\savedAddresses.txt", true))
        {
            file.WriteLine(s.latitude + " " + s.longitude);
            file.Close();
        }  

        return s;
   }

When I click on the button the file is created but nothing is saved into it.
Am I doing this right or is there a better way to try and write the user input into a file?

A:

I think you're getting confused on the web lifecycle. In your particular instance, this is what is happening:

Your page is requested, and the ASP.NET Runtime loads your code behind and attempts to execute the page. 
In the process of executing your page, the ASPX contains code to call 
 saveAddress s = save()

In this way, that method is called before the page is even rendered back to the client.
When the page is finally sent down to the client, you have some client side code invoking function save().

Im guessing you want that server side method to be invoked after the javascript function has run. You have two options:

Full PostBack - You post the form back to the server, and your ASPX code behind can have some code there to inspect Page.IsPostBack and attempt to call your server side method. 
Ajax - You can make an ajax request to a specific handler on your site and then invoke your server side save method. 

